Need your guidance on an issue I am facing currently. We have a web application, which have some asp.net web services(asmx) under sub directories of the application. Whenever we are configuring windows authentication at the application level, I was expecting that this setting would be inherited to all the asmx services in the child directories. But they still show their authentication mode as Anonymous authentication. In this state, when i try to access the web service, I get a 401.2 Unauthorized exception. I have to manually change the authentication mode of the service to windows to access that web service. We are also trying to automate this using Microsoft.Web.Administration dll.We are using
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection =
config.GetSection("system.webServer/security/authentication/anonymousAuthentication", siteName);
In the above code,siteName variable contains the path to the app like website/app Can anybody tell me how to set the windows authentication at asmx service level using ServerManager api?
I finally found a way to resolve this. The application host configuration file contains individual entries for each service or a folder. so, we have to provide appropriate path for individual service or a sub directory, if we have multiple services in a sub directory. So, the code will be like this
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection =
config.GetSection("system.webServer/security/authentication/anonymousAuthentication", siteName);
In the above example, just replace the site name with path to the service name or any sub directory under the application. This need to be done for all the sub directories under the application.