简体   繁体   中英

Application End after saving PDF file in ASP.net

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.

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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM