在ASP.net中保存PDF文件后,应用程序结束 [英] Application End after saving PDF file in ASP.net
问题描述
我创建了一个函数,该函数从会话中获取HTML数据并将其另存为PDF
为此,我使用了 NReco.PdfGenerator
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;
}
}
我没有遇到有关PDF生成的任何问题,但是,执行此函数后,它直接在 Global.asax
中调用 Application_End
我已经尝试过在应用程序中遇到任何错误,但 Application_Error
无法执行.
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.
推荐答案
经过长时间的搜索和搜索,我发现我将文件保存在项目中包含的 PDF
文件夹中.
因此,每生成一个新的PDF文件时,文件夹更改中的每个 15-20
更改之后,文件夹更改中的 AppDomain
recycle
都会运行,这些文件包含在解决方案所包含的项目中.因此我通过在 web.cofig
文件中添加 fcnMode ="Disabled"
来找到解决方案,如下所示.
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" />
这篇关于在ASP.net中保存PDF文件后,应用程序结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!