当前位置:首页 > 服务器技术 > IIS

c# – 如何在.NET Web服务上以编程方式在IIS中设置集成Windows身份验证?

我有一个Web服务项目需要设置为在安装后使用集成Windows身份验证.通常,我会安装Web服务,然后手动转到IIS并确保选中“集成Windows身份验证”框.必须有一种方法可以通过代码执行此操作.我已经查看了使用Installer类.看起来这是我可以使用的东西,但我没有在IIS中以编程方式设置属性.

解决方法:

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();

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!