Brzmi jak twój nadzieję na zmianę konfiguracji systemu informacji Internet na miejscu; czy to jest poprawne coś jak to powinno działać:
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();
}
Powyższy kod będzie można utworzyć regułę autoryzacji, który pozwala użytkownikowi w konkretnej grupie, aby uzyskać dostęp do konkretnej witryny. W tym przypadku strona to Contoso.
Wtedy to wyłączyć uwierzytelnianie Anonymous na miejscu; następnie włączyć Podstawowe & uwierzytelniania systemu Windows dla strony:
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();
}
Albo można po prostu dodać konto użytkownika IIS Manager, jeśli chcesz; które można ustawić na określone uprawnienia do manipulowania i zarządzania tymi innymi aplikacjami.
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"] = @"[email protected]";
addElement["enabled"] = true;
credentialsCollection.Add(addElement);
serverManager.CommitChanges();
}
Istnieje wiele elastyczności w ramach Internet Information System; jest dość potężny. Dokumentacja przez odniesienie jest również dość głęboka. Te przykłady są dość nieudolny być dostosowane do konkretnego użycia lub przynajmniej zapewnić poziom zrozumienia, aby to zrobić, co chcesz.
Mam nadzieję, że pomoc, te przykłady pochodziły z here: