我有一个 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();
关于c# - 如何以编程方式在 .NET Web 服务的 IIS 中设置集成 Windows 身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2661425/