HttpWebRequest 401错误 [英] HttpWebRequest 401 error

查看:384
本文介绍了HttpWebRequest 401错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Intranet应用程序(Windows身份验证),该应用程序从报告服务器下载报告流,然后将其另存为文件.当我在调试模式下运行它时,它可以正常工作.代码如下:

I am developing an intranet application (Windows Authentication) which download report stream from reporting server then save it as a file. When I ran it in debuging mode it works fine。 The code is as below:

       HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

       req.UseDefaultCredentials = true; 

        HttpWebResponse response = (HttpWebResponse)req.GetResponse();
        Stream fStream = response.GetResponseStream();

但是,当我将其部署到服务器后,它不会得到响应,而不是得到401未经授权的错误.

However after I deployed it to the server, it won't get response rather than getting 401 unauthorized error.

即使我将代码更改为: HttpWebRequest req =(HttpWebRequest)WebRequest.Create(url);

Even I change the code to: HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

        string domain = ConfigurationManager.AppSettings["SchedulerDomain"];
        string userName = ConfigurationManager.AppSettings["SchedulerUser"];
        string passWord = ConfigurationManager.AppSettings["SchedulerPassword"];
        NetworkCredential credential = new System.Net.NetworkCredential(userName, passWord, domain);
        req.Credentials = credential;

         HttpWebResponse response = (HttpWebResponse)req.GetResponse();
        Stream fStream = response.GetResponseStream();

得到同样的错误.代码中的用户设置有权查看/运行报告.

Get the same error. The user setup in the code has the permission to view/run the report.

IIS7正在使用协商和NTLM. (由于复杂原因,无法更改Kerberos),在ApplicationPoolIdentity下运行

The IIS7 is using Negotiate and NTLM. (Due to complicated reason, can't change Kerberos), run under ApplicationPoolIdentity

我的问题是,当我在调试模式下运行它时,用户是我的Windows帐户,但是为什么在我尝试将凭据发送到报表服务器时却失败了?

My question is, when I run it under debug mode, the user is my windows account, but why it fails when I tried to send the credential to the reporting server?

任何人都可以帮忙吗?

推荐答案

我不确定IIS的配置方式,但似乎应用程序的应用程序池"中的身份"设置将覆盖所有提供的凭据.最明显的是,尝试与其进行身份验证的用户没有访问权限.话虽这么说,转到您的IIS管理器并检查站点的应用程序池"的身份"设置.

I'm not sure how your IIS is configured but it seems like the Identity in your Application Pools setting for your app is overriding any supplied credential. Most obviously, the user that it is trying to authenticate with does not have access. That being said go to your IIS Manager and check the Identity settings for the site's Application Pool.

将其更改为有权访问报告查看器并应修复的用户.我有一个类似的问题,我曾在此处发布,以防有​​人感兴趣的.

Change it to a user that has access to the report viewer and that should fix it. I've had a similar issue I posted here in case anyone is interested.

这篇关于HttpWebRequest 401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆