简体   繁体   中英

Programmatically set IIS Authentication model for a specific asp.net file

I need to set the Authentication model of a specific asp.net file in my IIS webservice application. Topic "How do I programmatically set Integrated Windows Authentication in IIS on a .NET web service?" basically does what I want, but for an entire site. I need to have all but one of my webservices anonymous access, but one needs to use "Windows Authentication"

Like So:

在此处输入图片说明

I cannot figure out how to specify a certain file when applying this code:

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

you can use the location node of the web.config file to configure specific directories/files of the application. or if you don't want to clutter the root web.config you can create additional web.config files in the sub-directories.

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