3

我可以在这里看到如何启用匿名身份验证并专门为凭据设置用户名和密码。谁能告诉我是否可以使用 .NET 来设置凭据以改用应用程序池的身份?我没有看到以编程方式做到这一点的方法。

在此处输入图像描述

    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
4

1 回答 1

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" ] = "";
于 2015-08-26T13:42:53.363 回答