简体   繁体   中英

How do I programmatically set Integrated Windows Authentication in IIS on a .NET web service?

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

Take a look at WebDeploy . This technology is designed by MS to, umm, deploy web apps. ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM