在我的ASP.NET MVC 5应用程序中,我有以下方法:
public ActionResult SendMailAsAStudent(string studentId, string companyId, int applicationId, string companyCVR, string studentCPR)
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var student = manager.FindById(studentId);
var company = manager.FindById(companyId);
var application = db.Applications.Find(applicationId);
Project projectobj = db.Projects.Find(application.ProjectId);
var myMessage = new SendGridMessage();
myMessage.From = new MailAddress("info@leepio.dk");
myMessage.AddTo(student.Email);
myMessage.AddTo(company.Email);
myMessage.Subject ="The contract for " + projectobj.Title + " is signed!";
myMessage.Html = "Here is the final contract";
LocalReport localReport = new LocalReport();
localReport.ReportPath = Server.MapPath("~/Contracts/Contract.rdlc");
ReportParameter cvrParameter = new ReportParameter("cvrParameter", companyCVR);
ReportParameter companyNameParameter = new ReportParameter("companyNameParameter", company.CompanyName);
ReportParameter companyAddressParameter = new ReportParameter("companyAddressParameter", company.Address);
ReportParameter studentNameParameter = new ReportParameter("studentNameParameter", student.FirstName+" "+student.LastName);
ReportParameter studentAddressParameter = new ReportParameter("studentAddressParameter", student.Address);
ReportParameter studentZipCodeParameter = new ReportParameter("studentZipCodeParameter", student.ZipCode);
ReportParameter jobStartDateParameter = new ReportParameter("jobStartDateParameter", projectobj.StartDate);
ReportParameter jobEndDateParameter = new ReportParameter("jobEndDateParameter", projectobj.EndDate);
ReportParameter jobDescriptionParameter = new ReportParameter("jobDescriptionParameter", projectobj.Description);
ReportParameter jobHoursPerWeekParameter = new ReportParameter("jobHoursPerWeekParameter", projectobj.HoursPerWeek.ToString());
ReportParameter jobHourlyRateParameter = new ReportParameter("jobHourlyRateParameter", projectobj.HourlyRate.ToString());
ReportParameter cprParameter = new ReportParameter("cprParameter", studentCPR);
localReport.SetParameters(new ReportParameter[] { cprParameter });
localReport.SetParameters(new ReportParameter[] { cvrParameter });
localReport.SetParameters(new ReportParameter[] { companyNameParameter });
localReport.SetParameters(new ReportParameter[] { companyAddressParameter });
localReport.SetParameters(new ReportParameter[] { studentNameParameter });
localReport.SetParameters(new ReportParameter[] { studentAddressParameter });
localReport.SetParameters(new ReportParameter[] { studentZipCodeParameter });
localReport.SetParameters(new ReportParameter[] { jobStartDateParameter });
localReport.SetParameters(new ReportParameter[] { jobEndDateParameter });
localReport.SetParameters(new ReportParameter[] { jobDescriptionParameter });
localReport.SetParameters(new ReportParameter[] { jobHoursPerWeekParameter });
localReport.SetParameters(new ReportParameter[] { jobHourlyRateParameter });
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension = "pdf";
Warning[] warnings;
string[] streams;
var renderedBytes = localReport.Render(reportType, "", out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
Response.AddHeader("content-disposition", "attatchment; filename=Contract." + fileNameExtension);
MemoryStream stream = new MemoryStream(renderedBytes);
myMessage.AddAttachment(stream, "Contract.pdf");
var apiKey = "key removed for this post";
var transportWeb = new Web(apiKey);
transportWeb.DeliverAsync(myMessage);
Contract contract = new Contract();
contract.StudentId = studentId;
contract.CompanyId = companyId;
contract.CVR = companyCVR;
contract.ApplicationId = applicationId;
contract.IsSigned = true;
db.Contracts.Add(contract);
db.SaveChanges();
return RedirectToAction("Index", "Projects");
}
如果我在localhost上运行它,它会成功发送带有报告文件的邮件。部署到Azure时,它不再有效。评论报告生成并将其添加为附件使其工作,因此我指出问题是围绕报告生成。
什么可能导致它不再在网站上工作?我已经检查了参数是否为空。
答案 0 :(得分:1)
我打开了web.config中显示的错误,如下所示:
<customErrors mode="Off">
然后我收到了错误:
Could not load file or assembly 'Microsoft.ReportViewer.ProcessingObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
感谢Crowcoder我终于发现了问题,我不得不从NuGet包管理器安装Microsoft.Report.Viewer 10.0.0!
构建,发布,现在可以使用了!