How do I render a remote ReportViewer aspx page in MVC4?

后端 未结 3 1839
自闭症患者
自闭症患者 2020-12-15 10:09

I\'m working on an MVC4 application that needs to render a remote report from SSRS using the ReportViewer. With help from this forum, I\'ve managed to get the page to render

3条回答
  •  温柔的废话
    2020-12-15 10:37

    In the end, I ended up having to ditch both my original answer and the callbacks criteria due to the unacceptable security risks. In my case, I wrote controller code rendering the report as HTML to a byte array and from there to a FileContentResult that MVC was kind enough to render as a static HTML page. Exporting as PDF, Excel, or any other options will eventually be implemented in a similar method by changing the Render parameter from HTML4.0 to whatever is appropriate (PDF,XLS) and the MIME type. This approach works with SQL Server 2008R2 and beyond. I haven't tried it with previous versions of SQL Server.

    [OutputCache(Duration = 120, VaryByParam = "id")]
    public ActionResult ExportHTML(int id)
    {
        // we need to add code to check the user's access to the preliminary report.
        // Also need to consolidate code between ExportHTML and ExportPDF.
        var userid = ;
        var password = ;
        var domain = ;
        IReportServerCredentials irsc = new myApp.Models.CustomReportCredentials(userid,
            password, domain);
        var parametersCollection = new List();
        parametersCollection.Add(new ReportParameter("Snapshot", id.ToString(), false));
        ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer();
        rv.ProcessingMode = ProcessingMode.Remote;
        rv.ServerReport.ReportServerCredentials = irsc;
        rv.ServerReport.ReportPath = ;
        rv.ServerReport.ReportServerUrl = new Uri("http://localhost/ReportServer");
        rv.ServerReport.SetParameters(parametersCollection);
    
        rv.ServerReport.Refresh();
        byte[] streamBytes = null;
        string mimeType = "";
        string encoding = "";
        string filenameExtension = "";
        string[] streamids = null;
        Warning[] warnings = null;
    
        streamBytes = rv.ServerReport.Render("HTML4.0", null, out mimeType, out encoding,
                                             out filenameExtension, out stream ids,
                                             out warnings);
        var HTMLReport = File(streamBytes, "text/html");
        return HTMLReport;
    }
    

提交回复
热议问题