我在MVC4 web应用程序中实现了RDLC报告(返回pdf文件字节)。无论用户何时请求报告,Web应用程序都会停止对所有用户的所有其他请求,除非此报告已呈现。有些报告大约100页左右,所以Web服务器需要一段时间才能生成并呈现报告。在此期间,Web服务器无法处理其他请求。假设Web服务器正忙于渲染报告,并且在一个新选项卡中尝试请求一些其他数据,除非该RDLC完成其操作,否则它将不会显示。在开发机器中也是如此。请有人建议这是我的Web应用程序中的设计缺陷还是这是默认行为?MVC4 RDLC停止所有其他请求
有没有一种方法可以解决这个多线程或多任务?
这是报告渲染代码,以防万一,如果你想看到。但我只想让其他人分享他们的经验。
public byte[] RenderReport(PageType pageType, string ReportFormat, string ReportPath, ReportDataSource[] ReportDataModelList, out string mimeType, ReportParameter[] ReportParameters)
{
LocalReport lr = new LocalReport();
string path = Path.Combine(ReportPath);
lr.ReportPath = path;
foreach (ReportDataSource rds in ReportDataModelList)
{
lr.DataSources.Add(rds);
}
lr.EnableExternalImages = true;
lr.SetParameters(new ReportParameter("PrintedBy", PrintedBy));
foreach (ReportParameter rp in ReportParameters)
lr.SetParameters(rp);
string encoding;
string fileNameExtension;
string pageWidthHeight;
if (pageType == PageType.Portrait)
pageWidthHeight =
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>";
else if (pageType == PageType.Landscape)
pageWidthHeight =
" <PageWidth>11in</PageWidth>" +
" <PageHeight>8.5in</PageHeight>";
else
pageWidthHeight =
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>";
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + ReportFormat + "</OutputFormat>" +
pageWidthHeight +
" <MarginTop>0.3in</MarginTop>" +
" <MarginLeft>0.3in</MarginLeft>" +
" <MarginRight>0.3in</MarginRight>" +
" <MarginBottom>0.3in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr.Render(
ReportFormat,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return renderedBytes;
}
谢谢。
请张贴相关的代码,并确切地显示问题出在哪里。 –
@learner我已经发布了代码,但没有什么特别的代码。我只想知道mvc rdlc的默认行为。 –