Application End after saving PDF file in ASP.net

走远了吗. 提交于 2020-04-16 04:08:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!