【发布时间】: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