I have been looking for a solution for doing reporting in ASP.Net MVC, and I did come across a solution by Rai Kaimal Rendering an RDLC directly to the Response stream in ASP.NET MVC. Everything works just fine, but the localReport.Render() function takes extremely long to render the page (40 seconds for 2 very simple pages - the same reports executes in 2 seconds from a winforms solution). Any help would be appreciated. If there's no way to speeding up the report, I'm interested in knowing how other developers handle the reporting in a ASP.Net MVC solution.
Here is my code:
public ActionResult CustomerReport()
{
var localReport = new LocalReport
{
ReportPath = Server.MapPath("~/Reports/CustomerReport.rdlc")
};
var reportDataSource = new ReportDataSource("Customers", _repository.GetAll( ));
localReport.DataSources.Add(reportDataSource);
const string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
const string deviceInfo = "<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
//Render the report
byte[] renderedBytes = localReport.Render(
reportType,
deviceInfo,
开发者_StackOverflow out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
Placing <trust legacyCasModel="true" level="Full"/>
inside <system.web>
tag in web.config
did it for me. I'm in ASP.NET Webforms though. More details here
精彩评论