C# 在ASP.net中保存PDF文件后应用程序结束
我创建了一个从会话中获取HTML数据并将其保存为PDF的函数C# 在ASP.net中保存PDF文件后应用程序结束,c#,asp.net,pdf-generation,nreco,C#,Asp.net,Pdf Generation,Nreco,我创建了一个从会话中获取HTML数据并将其保存为PDF的函数 为此,我使用了NReco.PdfGenerator private static string savePdf() { if (HttpContext.Current.Session["ReservationPrintHtml"] != null) { StringBuilder objStringBuilder = ((StringBuilder)HttpContext.Current.Session
为此,我使用了
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\u End
如果我在应用程序中遇到任何错误,但application\u error
未执行,我已尝试过
有人知道问题出在哪里吗?
谢谢。经过长时间的搜索和谷歌搜索,我发现我正在将文件保存在项目中包含的PDF
文件夹中。
因此,每当在文件夹更改中生成新的PDF文件时,都要在包含解决方案的项目中包含的文件夹中的每个15-20
更改后运行。
所以我通过在web.cofig
文件中添加fcnMode=“Disabled”
找到了解决方案,如下所示
<httpRuntime targetFramework="4.5.2" fcnMode="Disabled" />