.net - 将 IIS 网站应用程序设置为使用应用程序池身份进行匿名身份验证(通过代码)

标签 .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

最佳答案

迟到的回复(希望它会对某人有所帮助)您可以将其设置为使用应用程序池身份,只需将配置的该部分的用户名和密码设置为空白即可,例如

(请原谅 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" ] = "";

关于.net - 将 IIS 网站应用程序设置为使用应用程序池身份进行匿名身份验证(通过代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16964440/

相关文章:

.net - 当项目面向 3.5 时,Msbuild 4.0 是否引用 System.Core 4.0?

c# - 使用 DotNet HighCharts dll 在代码隐藏中制作图表

c# - 为 Windows 7 及更高版本编译 C# 程序

.net - 设置每个操作的 MaxAllowedContentLength/maxRequestLength 值

php - 使用户无法访问 'sitemap.xml',但机器人可以访问

.net - 用于选择 INI 部分的正则表达式仅选择 .NET 中的部分标题

.net - 套接字队列问题?

iis-7 - IIS 7是否有同时请求的限制?

iis-7 - IIS 7 默认使用哪个版本的 SSL,如何强制它使用 SSL v3?

wcf - 在WCF服务/登台中调试HTTP 500(内部服务器错误)