将凭据从 ASP.NET C# 传递到另一个 Web 服务
我正在运行一页 ASP.NET 4.0 C# 脚本。在调试模式下,我的脚本工作得很好,但是当我发布它时,它似乎在发出 WebRequest 时没有发送凭据。 以下是我正在使用的代码,我已经尝试了很多方法,但是当我使用我发布的脚本版本时,我不断收到 401 Unauthorized 错误。顺便说一句,我正在使用 IIS 7
WebRequest fwRequest = HttpWebRequest.Create(fwURL);
fwRequest.UseDefaultCredentials = true;
//fwRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse myHttpWebResponse = (HttpWebResponse)fwRequest.GetResponse();
I have a one page ASP.NET 4.0 C# script running. In debug mode my script works just fine but when I publish it, it seems like it is not sending the credentials when making the WebRequest.
The following is the code I am using, I have tried a bunch of things but I keep getting a 401 Unauthorized when I am using my published version of the script. BTW I am using IIS 7
WebRequest fwRequest = HttpWebRequest.Create(fwURL);
fwRequest.UseDefaultCredentials = true;
//fwRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse myHttpWebResponse = (HttpWebResponse)fwRequest.GetResponse();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调试时,您的项目使用您的凭据,但当您发布它时,它将使用 ASP.NET 用户的凭据或 IIS 配置中设置的凭据。
因此,不,您不能将客户端的凭据传递给另一个 Web 服务/应用程序,除非您说服他/她将用户名密码传递给您的应用程序(除非两个 Web 应用程序位于同一台计算机上)。
While debugging, your project use your credentials, but when you publish it it will use the credentials of ASP.NET user, or the credentials set in IIS configuration.
So no, you can not pass credentials of your client to another web service/appliaction unless you convince him/her to pass username-password to your application (Except that both web apps are on the same machine).