尝试从 ASP.NET 调用外部 Web 服务返回 401 - DefaultCredentials 为空

发布于 2024-08-30 23:55:43 字数 1059 浏览 1 评论 0原文

失败:

//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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文