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

Rus*_*uss 6 powershell windows-authentication iis-7.5

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

我被告知,并且没有发现相反的证据,当与Windows Auth一起使用时,NTLM提供程序比协商更快.这可能与Silverlight 4,.NET 3.5,Windows 2003 Active目录和IIS6结合使用,也可能不兼容.

由于此声明告诉我,我们已升级到IIS7.5(Server 2008R2),SilverLight 5和.NET 4.5,但AD仍在2003功能级别运行.

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

谢谢

Per*_*255 17

使用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>
Run Code Online (Sandbox Code Playgroud)

通过在按优先级顺序添加提供程序之前执行清除更改.

首先禁用匿名身份验证并启用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"}
Run Code Online (Sandbox Code Playgroud)

然后添加<clear />标签:

Remove-WebConfigurationProperty -PSPath IIS:\ -Location MySite -filter system.webServer/security/authentication/windowsAuthentication/providers -name "."
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)


Kev*_*Kev 3

您只能启用和禁用以下部分下可用的身份验证方法:

\n\n
\n

system.webServer/authentication

\n
\n\n

这是因为system.webServer/authentication它不是集合并且不支持addremoveconfig 元素。查看 IIS 配置架构文件:

\n\n
\n

C:\\Windows\\System32\\inetsrv\\config\\schema\\IIS_schema.xml

\n
\n\n

搜索一下system.webServer/security/authentication,您将看到该部分的每个子元素都被显式定义,并且其本身没有定义system.webServer/security/authentication

\n\n

关于排序,尝试更改身份验证方法顺序没有任何区别。例如,按以下顺序(基本在 Windows 身份验证之前):

\n\n
<system.webServer>\n    <security>\n        <authentication>\n            <basicAuthentication enabled="true" />\n            <windowsAuthentication enabled="true" />\n        </authentication>\n    </security>\n</system.webServer>\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我交换订单时:

\n\n
<system.webServer>\n    <security>\n        <authentication>\n            <windowsAuthentication enabled="true" />\n            <basicAuthentication enabled="true" />\n        </authentication>\n    </security>\n</system.webServer>\n
Run Code Online (Sandbox Code Playgroud)\n\n

...总是会导致 IIS 在 401 挑战中向浏览器发送以下标头(使用 Fiddler 捕获):

\n\n
HTTP/1.1 401 Unauthorized\nServer: Microsoft-IIS/7.5\nWWW-Authenticate: Negotiate\nWWW-Authenticate: NTLM\nWWW-Authenticate: Basic realm="172.16.3.87"\n
Run Code Online (Sandbox Code Playgroud)\n\n

在上面,IIS 向浏览器表明它支持 Kerberos、NTLM 或 Basic 身份验证方法。无论浏览器供应商如何(我尝试过 IE 和 Chrome),开箱即用的这些身份验证方法始终按此顺序排列。

\n\n

根据我使用 Fiddler 的观察,IE 和 Chrome 都尝试使用该浏览器支持的第一个可用方法进行协商。即在这种情况下 IE 和 Chrome 都协商了 Kerberos 身份验证:

\n\n
GET http://172.16.3.87:81/ HTTP/1.1\nHost: 172.16.3.87:81\nConnection: keep-alive\nAuthorization: Negotiate TlRMTVNTUAABAAAAl4II4gAAAAAAAAAAAAAAAAAAAAAGAbEdAAAADw==\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果您对它的Negotiate值进行 Base64 解码,则显示:

\n\n
NTLMSSP\n
Run Code Online (Sandbox Code Playgroud)\n\n

可以通过执行以下操作来删除 Kerberos(协商)方法:

\n\n
<system.webServer>\n    <security>\n        <authentication>\n            <windowsAuthentication enabled="true">\n                <providers>\n                    <remove value="Negotiate" />\n                </providers>\n            </windowsAuthentication>\n            <basicAuthentication enabled="true" />\n        </authentication>\n    </security>\n</system.webServer>\n
Run Code Online (Sandbox Code Playgroud)\n\n

但是,尝试通过执行以下操作来更改这些顺序将不会产生任何效果:

\n\n
<system.webServer>\n\xc2\xa0 \xc2\xa0 <security>\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 <authentication>\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 <windowsAuthentication enabled="true">\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 <providers>\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 <remove value="Negotiate" />\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 <remove value="NTLM" />\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 <add value="NTLM" />\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 <add value="Negotiate" />\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 </providers>\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 </windowsAuthentication>\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 <basicAuthentication enabled="true" />\n\xc2\xa0 \xc2\xa0 \xc2\xa0 \xc2\xa0 </authentication>\n\xc2\xa0 \xc2\xa0 </security>\n</system.webServer>\n
Run Code Online (Sandbox Code Playgroud)\n\n

您仍将WWW-Authenticate:按照以下顺序收到标头:

\n\n
WWW-Authenticate: Negotiate\nWWW-Authenticate: NTLM\nWWW-Authenticate: Basic realm="172.16.3.87"\n
Run Code Online (Sandbox Code Playgroud)\n