"the target principal name is incorrect" 401 错误

"the target principal name is incorrect" 401 error

所以我们有一个小应用程序指向 2008 SSRS 服务器上的报告。

此应用程序正常运行,但由于我们向服务器添加了更多网站,我们已将网络应用程序绑定更改为不是服务器名称的内容。

这导致我们得到以下信息:

The target principal name is incorrect Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The target principal name is incorrect

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Win32Exception (0x80004005): The target principal name is incorrect] System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatus& statusCode) +2622099
System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob) +99
System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate) +767
System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials) +18
System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials) +146
System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo) +2279623
System.Net.HttpWebRequest.CheckResubmitForAuth() +3031261
System.Net.HttpWebRequest.CheckResubmit(Exception& e) +169

[WebException: The remote server returned an error: (401) Unauthorized.]

我们为 运行 应用程序的 ID 添加了新绑定名称的 spn 到 SSRS 服务器,但什么也没有。

我看到很多人在执行此操作时遇到 SSPI 问题,但没有出现 401 错误。

我们使用的 ID 可以完全访问这两个框,如果您可以毫无问题地直接从 Web 服务器转到 SSRS。只有当它包裹在应用程序中时,我们才会收到错误。

有没有人运行以前处理过这个问题?

谢谢

所以我相信你的 webapp 有一个自定义主机名而不是服务器名(如果我在这里错了请纠正我)。

您需要验证的第一件事是此主机名是 A Record 还是 CName 。您可以对主机名执行 ping 命令并查看

  1. 如果它首先解析为服务器名称,然后是 ip - CName。 在这种情况下您不需要新的 SPN,您需要确保原始 SPN(具有机器名称的那个)使用与应用程序池相同的身份
  2. 如果直接解析为服务器 IP,则需要 SPN 您需要一个新的 SPN,并且需要确保应用程序池标识和 SPN 标识相同。确保 useAppPoolCredentials = true (IIS Manager -> web Site -> Configuration Editor -> system.webServer/security/authentication/windowsAuthentication)

所以我确实找到了答案,这是一个双跳认证问题。

你可以在那里找到更好的描述,但基本上网站会尝试验证两次(一次到网络服务器,一次到 SQL 服务器)但是,Windows 只会通过你的登录和密码一次。之后,它只传递ID。

解决方案是您需要让应用程序的应用程序池使用启用 Kerberos 的 ID,就像您在使用负载平衡时需要的那样。