【问题标题】:IE10 always shows cached PDF documentsIE10 总是显示缓存的 PDF 文档
【发布时间】:2015-01-04 09:14:50
【问题描述】:

我有一个 asp.net 应用程序,它根据 aspx 页面中的一些数据在单击按钮时动态生成 pdf 文件。

这在 IE8 上运行得很好,但现在在 IE10 中,用户总是得到缓存版本,并没有得到最新的 pdf,并且每次用户必须清除临时 Internet 文件才能获得最新版本。

这快把我逼疯了!请帮忙!

请注意:F5、ctrl+F5、更改 IE 缓存属性以每次都加载新页面不是一个选项,因为我不能要求每个用户都这样做!

我把它写到水晶报表模板中,并以pdf的形式导出到服务器上的本地文件夹,然后在浏览器中使用javascript打开(window.open())

相关代码如下:

     string fileName = "PCT_" + this.ContractNoTextBox.Text.Trim() + "_" + this.ContractTypeList.SelectedValue[0] + "_" + this.VersionTextBox.Text.Trim();

            string physicalFilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "ExportData\\" + fileName + ".pdf";
            //Delete the file if it exists
            if (File.Exists(physicalFilePath))
            {
                File.Delete(physicalFilePath);
            }

            reportdocument.ExportToDisk(ExportFormatType.PortableDocFormat, physicalFilePath);
            string filePathToExport = Request.Url.AbsoluteUri.Remove(Request.Url.AbsoluteUri.LastIndexOf("/")) + @"/ExportData/" + fileName + ".pdf";

            string openFileScript = "window.open('" + filePathToExport + "', '_blank');";

PS:这实际上在我在本地主机上调试时有效,仅在我将其部署在服务器上时才有效。

请帮忙!!

【问题讨论】:

  • 您可以将缓存过期(这是响应的标头)设置为过去的日期。向请求的 url 添加缓存破坏器也可以。

标签: javascript asp.net internet-explorer pdf crystal-reports


【解决方案1】:

我猜这是最好的解决方案,适用于任何地方! Right way to have ASP.NET / IIS NOT cache PDF files

但我仍然想知道当我在 Visual Studio 中调试时它有什么不同!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多