问题
I created one function which get HTML data from session and save that as PDF
for that I used NReco.PdfGenerator
private static string savePdf()
{
if (HttpContext.Current.Session["ReservationPrintHtml"] != null)
{
StringBuilder objStringBuilder = ((StringBuilder)HttpContext.Current.Session["ReservationPrintHtml"]);
string dir = HostingEnvironment.MapPath("~/Pdf");
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
string fileName = "PDF-" + DateTime.Now.ToString("yyyyMMdd-HHMMssffffff") + ".pdf";
string downloadFile = Path.Combine(dir, fileName);
string htmlContent = objStringBuilder.ToString();
byte[] pdfBytes = (new NReco.PdfGenerator.HtmlToPdfConverter()).GeneratePdf(htmlContent);
File.WriteAllBytes(downloadFile, pdfBytes);
return fileName;
}
else
{
return null;
}
}
I'm not facing any issue regarding PDF generation but, After this function execution it directly calls Application_End
in Global.asax
I have tried if I get any error in application but Application_Error
not execute.
Can anyone have idea what is the problem?
Thank you.
回答1:
After long search and googling I found that I'm saving files in PDF
folder which was included in my project.
So whenever new PDF file was generated AppDomain
recycle
on folder change run after every 15-20
changes in folders which are included in solution included projects.
so I found solution by adding fcnMode="Disabled"
in web.cofig
file like below.
<httpRuntime targetFramework="4.5.2" fcnMode="Disabled" />
来源:https://stackoverflow.com/questions/41737133/application-end-after-saving-pdf-file-in-asp-net