c# - Web 服务凭证从远程工作,但不在服务器上
问题描述
我正在调用一个 Web 服务(名为 SecurityService),如下所示:
SecurityService.Service securityService = new SecurityService.Service();
securityService.Credentials = networkCredential;
return securityService.GetUserToken();
该服务启用了 Windows 身份验证,仅此而已。上面的这段代码工作,来自远程机器。
当我将相同的代码推送到运行此服务的 IIS 服务器时,我收到 401 错误:
The request failed with HTTP status 401: Unauthorized.
我用 WCF 尝试了相同的代码:
ServiceSoapClient client = new ServiceSoapClient();
client.ClientCredentials.Windows.ClientCredential = networkCredential;
return client.GetUserToken();
使用这些设置:
<binding name="ServiceSoap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
</security>
</binding>
同样,在服务器上,我无法从连接到该服务器的另一台机器上对其进行身份验证,它可以工作。
以下是 Web 服务的高级日志记录捕获的标头:
当它工作时:
sc-win32-status WWW-Authenticate Authorization
2147024891 "NTLM,Negotiate" -
0 - "Negotiate TlRMTVNTUAADAAAAGAAYAIoAAACi...."
当它失败时,从同一服务器中调用:
sc-win32-status WWW-Authenticate Authorization
2147024891 "NTLM,Negotiate" -
1073741715 "NTLM,Negotiate" "Negotiate ADAAAAGAAYAI4AAACiAaIBpgAAABoAGgBY..."
当我使用 WCF 时,我也收到了这条消息,而不是普通的 401 错误:
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'NTLM,Negotiate'. ---> The remote server returned an error: (401) Unauthorized.
错误1073741715的解释:
STATUS_LOGON_FAILURE (-1073741715 (0xC000006D))
The attempted logon is not valid. This is due to either an incorrect user name or incorrect authentication information.
不知何故,当我的代码从服务器内运行时,它没有正确地对 Web 服务进行身份验证。
这是指向同一问题的链接。答案并不适用:
解决方案
您需要向与您的 IIS 应用程序相关的 IIS Web 应用程序或 IIS 应用程序池提供您的用户凭据。
为了这
- 打开 IIS。
- 单击应用程序池
- 选择您的应用程序在其上运行的应用程序池
- 单击右窗格中的高级属性
- 在 Process Model 下找到 Identity 并单击
...
按钮 - 单击自定义帐户并在那里添加您的 Windows 帐户
- 单击确定并保存。
还要确保应用程序不使用自定义用户。或者单击 IIS 应用程序,然后单击右窗格中的高级设置。之后修改物理路径凭据和物理路径凭据登录类型
推荐阅读
- django - 使用 get_context_data() 方法检索 DetailView Django 中的依赖对象列表
- c# - 在 AddHttpMessageHandler 方法中访问会话值
- python - 如果语句检查数据库中是否存在给定表单字段作为搜索条件的表?
- javascript - 这个javascript有什么错误?
- java - Drools:如何设置多线程(multithreadEvaluation)7.34.0 -Java Maven Spring
- clojure - 为什么 conj 可以产生比通常预期相反的结果
- javascript - 为什么 var mysql = require('mysql'); 返回未定义
- javascript - 一个选择上的 jQuery onchange 函数,ajax 填充辅助选择。如何改回默认值?
- amazon-web-services - 为什么我无法从我的机器连接到 rds db
- redirect - IIS 将子目录重定向到同名的根级目录