尝试从 ASP.NET 调用外部 Web 服务返回 401 - DefaultCredentials 为空
失败:
//Note: webserviceProxy inherits from SoapHttpClientProtocol
//App Pool is running as a user with permissions to call the external webservice
var webserviceProxy = new webServiceProxy();
webserviceProxy.PreAuthenticate = true;
webserviceProxy.UseDefaultCredentials = true;
var returnVal = webServiceProxy.DoSomething(); //Fails with 401, webserviceProxy.Credendials shows an empty username, pass, and domain
有效:
//This code works, but I want to assign the current app pool's credentials to the webservice proxy's credentials. UsingDefaultCredentials doesn't work. The username, passoword, and domain are always null.
var webserviceProxy = new webServiceProxy();
webserviceProxy.PreAuthenticate = true;
webserviceProxy.Credentials = new NetworkCredential("user", "pass", "domain");
var returnVal = webServiceProxy.DoSomething(); //Fails with 401
如何使用 ASP.NET 应用程序池的身份进行外部 Web 服务调用?似乎没有办法将 System.Security.Principal.WindowsIdentity.GetCurrent() 转换为我可以用于此调用的内容。
谢谢!
Fails:
//Note: webserviceProxy inherits from SoapHttpClientProtocol
//App Pool is running as a user with permissions to call the external webservice
var webserviceProxy = new webServiceProxy();
webserviceProxy.PreAuthenticate = true;
webserviceProxy.UseDefaultCredentials = true;
var returnVal = webServiceProxy.DoSomething(); //Fails with 401, webserviceProxy.Credendials shows an empty username, pass, and domain
Works:
//This code works, but I want to assign the current app pool's credentials to the webservice proxy's credentials. UsingDefaultCredentials doesn't work. The username, passoword, and domain are always null.
var webserviceProxy = new webServiceProxy();
webserviceProxy.PreAuthenticate = true;
webserviceProxy.Credentials = new NetworkCredential("user", "pass", "domain");
var returnVal = webServiceProxy.DoSomething(); //Fails with 401
How can I make an external webservice call using the identtity of ASP.NET's app pool? There doesn't seem to be a way to convert System.Security.Principal.WindowsIdentity.GetCurrent()
to something I can use for this call.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这篇 Microsoft 支持文章可以帮助您解决问题:
您收到当您浏览使用集成身份验证并托管在 IIS 5.1 或更高版本上的网站时出现错误 401.1
最重要的是,当计算机名称和网站 FQDN 不匹配时,Windows 会保护自身。
另请参阅:
Maybe this Microsoft support article can help you solving the issue:
You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version
The bottom line is that Windows will protect itself when the machine name and web site FQDN do not match.
Also see: