【问题标题】:Application End after saving PDF file in ASP.net在 ASP.net 中保存 PDF 文件后应用程序结束
【发布时间】:2017-01-19 08:31:04
【问题描述】:

我创建了一个从会话中获取 HTML 数据并将其保存为 PDF 的函数
为此我使用了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 未执行,我已经尝试过。

谁能知道问题出在哪里?
谢谢。

【问题讨论】:

    标签: c# asp.net pdf-generation nreco


    【解决方案1】:

    经过长时间的搜索和谷歌搜索,我发现我将文件保存在我的项目中包含的 PDF 文件夹中。
    因此,每当 AppDomain recycle 生成新的 PDF 文件时,在包含在解决方案包含的项目中的文件夹中每次 15-20 更改后运行文件夹更改。 所以我通过在web.cofig 文件中添加fcnMode="Disabled" 找到了解决方案,如下所示。

    <httpRuntime targetFramework="4.5.2" fcnMode="Disabled" />
    

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 2014-08-02
      • 1970-01-01
      • 2013-09-20
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多