我有一个MVC Controller方法,它将rdlc报告的结果写入文件。这在我的本地计算机上工作正常,但是当它发布到生产时,它会停止在setparameters行上执行,并且不会触发异常。任何线索将不胜感激。
public JsonResult GenerateSignInSheet(string id)
{
try
{
string pgmid = id;
string strProgDate = "";
DateTime? dtProgDate = null;
Program prog = db.Programs.SingleOrDefault(p => p.ProgramID == pgmid);
if (prog != null)
dtProgDate = prog.ProgDate;
if (dtProgDate != null)
strProgDate = String.Format("{0:d}", dtProgDate);
string strProgLoc = string.Empty;
var locInfo = this.dc.usp_ProgramLocSiteInfo(id).SingleOrDefault();
if (locInfo != null) strProgLoc = locInfo.VendorOrHost ?? string.Empty;
//Rep information
string strRepName = string.Empty;
LocalReport localReport = new LocalReport();
// the following 2 lines will allow globals to work - MS gotcha
System.Security.PermissionSet sec = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
localReport.SetBasePermissionsForSandboxAppDomain(sec);
localReport.ReportPath = Server.MapPath("~/Content/Reports/RptSignInSheetPrefilled.rdlc");
var sourceList = dc.GetRSVPListForSignin(pgmid).ToList();
ReportDataSource reportDataSource = new ReportDataSource("DataSetRSVPList", sourceList);
ReportParameter p1 = new ReportParameter("ProgramID", pgmid);
ReportParameter p2 = new ReportParameter("ProgDate", strProgDate);
ReportParameter p3 = new ReportParameter("LocName", strProgLoc);
ReportParameter p4 = new ReportParameter("RepName", strRepName);
localReport.SetParameters(new ReportParameterCollection { p1, p2, p3, p4 });
localReport.DataSources.Add(reportDataSource);
//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
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>11in</PageWidth>" +
" <PageHeight>8.5in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>0.5in</MarginLeft>" +
" <MarginRight>0.5in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//Render the report
renderedBytes = localReport.Render(
"PDF",
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
string strPDFOutputPath = System.Configuration.ConfigurationManager.AppSettings["PDFDocumentsPath"].ToString();
string strPDFFilename = strPDFOutputPath + id.Replace("-", string.Empty) + ".pdf";
System.IO.FileStream fs = new System.IO.FileStream(strPDFFilename, System.IO.FileMode.Create);
fs.Write(renderedBytes, 0, renderedBytes.Length);
fs.Close();
fs.Dispose();
//var theFile = File(renderedBytes, mimeType);
return Json(new { File = strPDFFilename });
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
return Json(new { File = "" });
}
}
答案 0 :(得分:0)
你应该查看你的dll的版本。
我有同样的问题,我的情况(Asp.Net 4 Razor,MVC)需要第11版: