您只能启用和禁用以下部分中可用的身份验证方法:
system.webServer/authentication
这是因为system.webServer/authentication 不是集合,不支持add 和remove 配置元素。查看 IIS 配置架构文件:
C:\Windows\System32\inetsrv\config\schema\IIS_schema.xml
搜索system.webServer/security/authentication,您会看到该部分的每个子元素都已明确定义,system.webServer/security/authentication 本身没有定义。
关于排序,尝试更改身份验证方法的顺序没有区别。例如按以下顺序(基本在 Windows Authenticaton 之前):
<system.webServer>
<security>
<authentication>
<basicAuthentication enabled="true" />
<windowsAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
当我交换订单时:
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<basicAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
...总是会导致 IIS 在 401 质询中将以下标头发送到浏览器(使用 Fiddler 捕获):
HTTP/1.1 401 Unauthorized
Server: Microsoft-IIS/7.5
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="172.16.3.87"
在上面,IIS 向浏览器表明它支持 Kerberos、NTLM 或基本身份验证方法。开箱即用的这些身份验证方法始终按此顺序排列,与浏览器供应商无关(我尝试过 IE 和 Chrome)。
根据我使用 Fiddler 的观察,IE 和 Chrome 都尝试使用该浏览器支持的第一个可用方法进行协商。即在这种情况下,IE 和 Chrome 都协商了 Kerberos 身份验证:
GET http://172.16.3.87:81/ HTTP/1.1
Host: 172.16.3.87:81
Connection: keep-alive
Authorization: Negotiate TlRMTVNTUAABAAAAl4II4gAAAAAAAAAAAAAAAAAAAAAGAbEdAAAADw==
如果您对 Negotiate 值进行 base64 解码,它会显示:
NTLMSSP
可以通过以下方式删除 Kerberos (Negotiate) 方法:
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true">
<providers>
<remove value="Negotiate" />
</providers>
</windowsAuthentication>
<basicAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
但是尝试通过执行以下操作来更改这些顺序将无效:
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true">
<providers>
<remove value="Negotiate" />
<remove value="NTLM" />
<add value="NTLM" />
<add value="Negotiate" />
</providers>
</windowsAuthentication>
<basicAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
您仍将按以下顺序收到WWW-Authenticate: 标头:
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="172.16.3.87"