设置IIS网站应用程序以使用应用程序池标识进行匿名身份验证(通过代码)

时间:2013-06-06 14:15:43

标签: .net iis-7

I can see here如何启用匿名身份验证,并专门为凭据设置用户名和密码。任何人都可以告诉我,是否可以使用.NET来设置凭据以使用应用程序池的身份?我没有看到以编程方式执行此操作的方法。

enter image description here

    Public Sub CreateApplication(ByVal website As String, ByVal application As String, ByVal path As String, applicationPoolName As String)

        Using manager As New ServerManager()
            manager.Sites(website).Applications.Add("/" & application, path)
            manager.CommitChanges()
            manager.Sites(website).Applications("/" & application).ApplicationPoolName = applicationPoolName

            Dim config As Configuration = manager.GetApplicationHostConfiguration
            Dim anonymousAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", website & "/" & application)
            anonymousAuthenticationSection("enabled") = True
            manager.CommitChanges()
        End Using

    End Sub

1 个答案:

答案 0 :(得分:2)

延迟回复(希望它可以帮助某人)您可以将其设置为使用应用程序池标识,只需为配置的该部分设置用户名和密码为空白即可。

(原谅C#语法)

        var config = _IIS.GetApplicationHostConfiguration();
        var anonymousAuthenticationSection = config.GetSection( "system.webServer/security/authentication/anonymousAuthentication", name );
        anonymousAuthenticationSection[ "enabled" ] = true;
        //use app pool user
        anonymousAuthenticationSection[ "userName" ] = "";
        anonymousAuthenticationSection[ "password" ] = "";