asp.net-mvc - 在MVC操作中,将SSRS报告导出到 PDF

  显示原文与译文双语对照的内容
0 0

我想将SSRS报告导出到 PDF,并从我的操作返回它。我没有任何报告查看器。请告诉我如何实现这里功能。 到目前为止我已经做到了

 public void SqlServerReport()
 {
 NetworkCredential nwc = new NetworkCredential("username","password","domain");
 WebClient client = new WebClient();
 client.Credentials = nwc;
 string reportURL ="http://servername/ReportServer/reportfolder/StateReport&rs:Command=Render&rs:Format=PDF";
 Byte[] pageData = client.DownloadData(reportURL);
 Response.ContentType ="application/pdf";
 Response.AddHeader("Content-Disposition","attachment; filename=" + DateTime.Now);
 Response.BinaryWrite(pageData);
 Response.Flush();
 Response.End();
 }

上代码引发异常

"The remote server returned an error: (401) Unauthorized."

我的问题是
1 ) 我的方向正确?
2 ) 是否有更好的替代方案来实现这里目的?

时间:原作者:2个回答

0 0

我更正了上面的代码,现在它的工作

 public ActionResult GetPdfReport()
 {
 NetworkCredential nwc = new NetworkCredential("username","password");
 WebClient client = new WebClient();
 client.Credentials = nwc;
 string reportURL ="http://someIp/ReportServer/?%2fReportProjectName/ReportName&rs:Command=Render&rs:Format=PDF";
 return File(client.DownloadData(reportURL),"application/pdf");
 }

我没有发现在MVC中导出SSRS报告的其他替代方法不使用 ReportViewer 。

原作者:
0 0

尝试不像这样指定域:

NetworkCredential nwc = new NetworkCredential("username","password");
原作者:
...