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 = <userid>;
var password = <password>;
var domain = <domain>;
IReportServerCredentials irsc = new myApp.Models.CustomReportCredentials(userid,
password, domain);
var parametersCollection = new List<ReportParameter>();
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 = <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;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…