以编程方式为特定的asp.net文件设置IIS身份验证模型

时间:2011-12-21 20:35:57

标签: asp.net iis

我需要在IIS webservice应用程序中设置特定asp.net文件的身份验证模型。主题“如何在.NET Web服务上以编程方式在IIS中设置集成Windows身份验证?”基本上做我想要的,但对于整个网站。我需要除了我的一个webservices匿名访问,但需要使用“Windows身份验证”

喜欢如此:

enter image description here

在应用此代码时,我无法弄清楚如何指定某个文件:

String applicationPath = String.Format("{0}/{1}", _server.Sites["Default Web Site"].Name, "AppName"); 

Configuration config = _server.GetApplicationHostConfiguration(); 

ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", applicationPath); 

anonymousAuthenticationSection["enabled"] = false; 

ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", applicationPath); 

windowsAuthenticationSection["enabled"] = true; 

_server.CommitChanges(); 

1 个答案:

答案 0 :(得分:0)

您可以使用web.config文件的location节点来配置应用程序的特定目录/文件。或者如果您不想使根web.config混乱,可以在子目录中创建其他web.config文件。

相关问题