The following example demonstrates how to disable anonymous authentication in IIS, and enable windows authentication.


using (ServerManager serverManager = new ServerManager())
{
Microsoft.Web.Administration.Configuration config = serverManager.GetApplicationHostConfiguration();
Microsoft.Web.Administration.ConfigurationSection anonymousAuthenticationSection = config.GetSection
("system.webServer/security/authentication/anonymousAuthentication", webSiteName + "/" + applicationName);
anonymousAuthenticationSection["enabled"] = false;
Microsoft.Web.Administration.ConfigurationSection windowsAuthenticationSection = config.GetSection
("system.webServer/security/authentication/windowsAuthentication", webSiteName + "/" + applicationName);
windowsAuthenticationSection["enabled"] = true;
serverManager.CommitChanges();
}

Advertisements