powershell - 如何使用 powershell 设置 IIS Windows 身份验证提供程序?

标签 powershell iis-7.5 windows-authentication

有没有办法可以在 IIS 7.5 中使用 powershell 添加/删除/重新排序 Windows 身份验证提供程序?

有人告诉我,并且没有发现任何相反的证据,NTLM 提供程序在与 Windows Auth 一起使用时比 Negotiate 更快。它可能会也可能不会与 Silverlight 4、.NET 3.5、Windows 2003 Active Directory 和 IIS6 结合使用。

自从我得知此消息后,我们已升级到 IIS7.5(Server 2008R2)、SilverLight 5 和 .NET 4.5,但 AD 仍运行在 2003 功能级别。

我的目标是始终确保 NTLM 提供程序在 IIS 7.5 中启用的提供程序列表中首先列出。

谢谢

最佳答案

可以使用 powershell 来完成此操作。 对于我正在使用的场景,我想配置特定站点而不是更改默认设置。 默认情况下,这在 web.config 中是不可能的,因为所有身份验证设置都设置为 overrideModeDefault="Deny"。这意味着需要直接对 applicationhost.config 进行更改。

我正在寻找的最终结果是:

<location path="MySite">
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="false" />
                <windowsAuthentication enabled="true">
                    <providers>
                        <clear />
                        <add value="NTLM" />
                        <add value="Negotiate" />
                    </providers>
                </windowsAuthentication>
            </authentication>
        </security>
    </system.webServer>
</location>

在按照更改的优先级顺序重新添加提供商之前,先执行清除操作。

要首先禁用匿名身份验证并启用 Windows 身份验证,我使用以下命令:

Set-WebConfiguration system.webServer/security/authentication/anonymousAuthentication -PSPath IIS:\ -Location MySite -Value @{enabled="False"}
Set-WebConfiguration system.webServer/security/authentication/windowsAuthentication -PSPath IIS:\ -Location MySite -Value @{enabled="True"}

然后添加<clear />标签:

Remove-WebConfigurationProperty -PSPath IIS:\ -Location MySite -filter system.webServer/security/authentication/windowsAuthentication/providers -name "."

最后,按顺序添加提供者:

Add-WebConfiguration -Filter system.webServer/security/authentication/windowsAuthentication/providers -PSPath IIS:\ -Location MySite -Value NTLM
Add-WebConfiguration -Filter system.webServer/security/authentication/windowsAuthentication/providers -PSPath IIS:\ -Location MySite -Value Negotiate

关于powershell - 如何使用 powershell 设置 IIS Windows 身份验证提供程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18319961/

相关文章:

powershell - 如何在 powershell 中的 try...catch block 中正确抛出数组

iis-7.5 - HTTP 错误 401.2 - 未经授权 由于身份验证 header 无效,您无权查看此页面

ssl - IIS 7.5 多个子域相同的通配符证书

windows-authentication - STS 不支持请求的身份验证方法

c - 新创建的用户上的 RegOpenCurrentUser(KEY_WRITE)

powershell - 从 run.exe 运行 powershell 命令

windows - 将用户对象ID写入变量#Powershell

PowerShell - 将刻度转换为时间

asp.net - ashx 处理程序 DELETE 请求不起作用 HTTP 405.0

azure-sql-database - 使用 Azure SQL DB 进行 SSMS Active Directory 身份验证