It looks like you are hoping to change the configuration of the Internet information system for the site; if this is correct, then something like this should work:
using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetWebConfiguration("Contoso"); ConfigurationSection authorizationSection = config.GetSection("system.webServer/security/authorization"); ConfigurationElementCollection authorizationCollection = authorizationSection.GetCollection(); ConfigurationElement addElement = authorizationCollection.CreateElement("add"); addElement["accessType"] = @"Allow"; addElement["roles"] = @"administrators"; authorizationCollection.Add(addElement); serverManager.CommitChanges(); }
The above code will allow you to create an authorization rule that allows a specific user in a group to access a specific site. In this case, the Contoso website.
This will then disable anonymous authentication for the site; then enable Basic and Windows Authentication for the site:
using(ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso"); anonymousAuthenticationSection["enabled"] = false; ConfigurationSection basicAuthenticationSection = config.GetSection("system.webServer/security/authentication/basicAuthentication", "Contoso"); basicAuthenticationSection["enabled"] = true; ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso"); windowsAuthenticationSection["enabled"] = true; serverManager.CommitChanges(); }
Or you can simply add an IIS Manager user account if you want; which you can set for specific permissions to manage and manage these other applications.
using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetAdministrationConfiguration(); ConfigurationSection authenticationSection = config.GetSection("system.webServer/management/authentication"); ConfigurationElementCollection credentialsCollection = authenticationSection.GetCollection("credentials"); ConfigurationElement addElement = credentialsCollection.CreateElement("add"); addElement["name"] = @"ContosoUser"; addElement["password"] = @" P@ssw0rd "; addElement["enabled"] = true; credentialsCollection.Add(addElement); serverManager.CommitChanges(); }
There is great flexibility in the Internet information system; its quite powerful. The documentation contained here is also quite detailed. The examples are pretty inappropriate to adapt to your specific use, or at least provide a level of understanding to get it to do what you want.
Hope this helps brought here :
source share