从C#代码下载报表服务器pdf

从C#代码下载报表服务器pdf,c#,model-view-controller,reporting-services,C#,Model View Controller,Reporting Services,因此,我遵循了这个站点()和其他各种站点的代码,但似乎没有任何效果。我想在mvc的网页上有一个链接,可以下载pdf格式的报告。当我浏览到这个url时,它工作得很好,但我一直收到这个错误:“远程服务器返回了一个错误:(401)未经授权。”在mvc中。这是我目前的代码: public ActionResult Download() { var url = "http://xxxx/ReportServer/Pages/ReportViewer.aspx?%2f

因此,我遵循了这个站点()和其他各种站点的代码,但似乎没有任何效果。我想在mvc的网页上有一个链接,可以下载pdf格式的报告。当我浏览到这个url时,它工作得很好,但我一直收到这个错误:“远程服务器返回了一个错误:(401)未经授权。”在mvc中。这是我目前的代码:

public ActionResult Download()
        {
            var url = "http://xxxx/ReportServer/Pages/ReportViewer.aspx?%2fxxx+xxx%2fxxx+Report&rs:Command=Render&CellNumber=";

            NetworkCredential nwc = new NetworkCredential("xxx", "xxx", "xxx");
            WebClient client = new WebClient();
            client.Credentials = nwc;
            client.UseDefaultCredentials = false;
            string reportURL = String.Format("{0}{1}{2}", url, Cellphone, "&rs:Format=PDF");
            return File(client.DownloadData(reportURL), "application/pdf");
        }
当我删除它授权的
“&rs:Format=PDF”
部分时,应用程序随后失败。
请提供帮助。

您确定pdf服务可以接受您构建的最终url吗?请使用此链接