Reputation: 256
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();
Upvotes: 0
Views: 740
Reputation: 7591
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.
Upvotes: 0