如何以编程方式在.NET Web服务设置集成Windows身份验证在IIS中? [英] How do I programmatically set Integrated Windows Authentication in IIS on a .NET web service?

查看:239
本文介绍了如何以编程方式在.NET Web服务设置集成Windows身份验证在IIS中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要设置安装后即可使用集成Windows身份验证的Web服务项目。通常情况下,我会安装Web服务,然后手动去IIS并确保复选框被选中了集成Windows身份验证。必须有一种方法,通过code做到这一点。我已经看过了如何使用安装程序类。看起来这是一件我可以使用,但我还没有发现在IIS编程设置属性东西。


解决方案

 字符串applicationPath =的String.Format({0} / {1},_server.Sites [默认Web网站。]的名称,APPNAME);配置配置= _server.GetApplicationHostConfiguration();的ConfigurationSection anonymousAuthenticationSection = config.GetSection(system.webServer /安全/认证/ anonymousAuthentication,applicationPath);anonymousAuthenticationSection [启用] = FALSE;的ConfigurationSection windowsAuthenticationSection = config.GetSection(system.webServer /安全/认证/ windowsAuthentication,applicationPath);windowsAuthenticationSection [启用] =真;_server.CommitChanges();

I have a web service project that needs to be set to use Integrated Windows Authentication after installation. Normally, I would install the web service, then manually go to IIS and make sure the box is checked for Integrated Windows Authentication. There has to be a way to do this through code. I have looked up on using the Installer class. It looks like this is something I could use, but I have not found anything on setting properties programmatically in 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();

这篇关于如何以编程方式在.NET Web服务设置集成Windows身份验证在IIS中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆