简体   繁体   English

接收到SSRS 2008的HttpWebRequest中的“未经授权(401)”错误

[英]Receiving “Unauthorized (401)” error in HttpWebRequest to SSRS 2008

I'm using HttpWebRequest to programatically export an SSRS 2008 report in PDF format. 我正在使用HttpWebRequest以编程方式导出PDF格式的SSRS 2008报告。 My problem however, is my NetworkCredentials don't seem to be working. 但是,我的问题是我的NetworkCredentials似乎不起作用。 I'm receiving an Unauthorized (401) error when trying access SSRS. 尝试访问SSRS时收到未授权(401)错误。

I know the NetworkCredentials I supplied are correct. 我知道我提供的NetworkCredentials是正确的。 If I log into our SSRS web service manually, these are the exact credentials I use. 如果我手动登录我们的SSRS Web服务,则这些是我使用的确切凭据。 Also, this works fine locally, just not up on our server. 另外,这在本地工作正常,只是在我们的服务器上没有。

The report is run on our asp.net 4.0 website. 该报告在我们的asp.net 4.0网站上运行。 When the user clicks the "Generate Report" button, the following code is executed (the error occurs on my 2nd line, on WebRequest.Create) to try to connect to my SSRS 2008: 当用户单击“生成报告”按钮时,将执行以下代码(该错误发生在我的第二行WebRequest.Create上)以尝试连接到我的SSRS 2008:

string sTargetURL = "MY_REPORT_SERVER?/REPORT_NAME&rs:format=pdf&rs:command=render&rc:parameters=Collapsed";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sTargetURL);
req.PreAuthenticate = true;

 req.Credentials = new NetworkCredential("Username", "Password", "Domain");

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

 byte[] fileBytes = ReadFully(fStream);
 HttpWResp.Close();

 System.Web.HttpContext.Current.Response.Clear();
 System.Web.HttpContext.Current.Response.ContentType = "application/pdf";

 System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=\"" + reportName + ".pdf"\"");
 System.Web.HttpContext.Current.Response.BinaryWrite(fileBytes);
 System.Web.HttpContext.Current.Response.Flush();
 System.Web.HttpContext.Current.Response.End();

Outside the application, are you able to run the report locally and in the Report Manager/Server? 在应用程序外部,您是否能够在本地以及在报表管理器/服务器中运行报表? If so, what type of data source does the report use? 如果是这样,报告将使用哪种类型的数据源? It could be that the data source does not accept the credentials double-hopping from the Report Server. 数据源可能不接受来自报表服务器的凭据两次跳跃。 You may need to create a domain account with the necessary read rights and configure the data source on the Report Server to impersonate these credentials. 您可能需要创建具有必要读取权限的域帐户,并在报表服务器上配置数据源以模拟这些凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM