Programmatically enable forms authentication in IIS 7.0

前端 未结 3 999
滥情空心
滥情空心 2021-01-16 06:22

I\'m currently using System.DirectoryServices.DirectoryEntry and the \'AuthFlags\' property therein to set Anonymous access to a virtual web. To enable anonymous access I g

3条回答
  •  情书的邮戳
    2021-01-16 07:01

    Source

    using System;
    using System.Text;
    using Microsoft.Web.Administration;
    
    internal static class Sample {
    
       private static void Main() {
    
          using(ServerManager serverManager = new ServerManager()) { 
             Configuration config = serverManager.GetApplicationHostConfiguration();
    
             ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso");
             anonymousAuthenticationSection["enabled"] = false;
    
             ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso");
             windowsAuthenticationSection["enabled"] = true;
    
             serverManager.CommitChanges();
          }
       }
    }
    

提交回复
热议问题