有ASP.NET正道/ IIS不缓存PDF文件 [英] Right way to have ASP.NET / IIS NOT cache PDF files

查看:191
本文介绍了有ASP.NET正道/ IIS不缓存PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的情况下,我想对什么是处理这种最好的方式提出建议。我的web应用程序(ASP.NET 2.0 / IIS 6)生成的PDF文件,并​​且我有链接到这些PDF的一个结果页面。

I have the following scenario, and I wanted suggestions on what is the best way to handle this. My web app (ASP.NET 2.0 / IIS 6) generates PDF files, and I have a results page with links to those PDFs.

现在,我注意到,如果我访问的结果页面,点击一个PDF文件(它在新窗口中打开),然后重新生成PDF文件,然后点击结果页面上,老在同一链路上PDF被示出,而不是新的,。我不得不删除才能看到新的Internet临时文件。

Now, I noticed that if I visit the results page, click on a PDF file (it opens in a new window), then re-generate the PDF file, and click on the same link in the results page, the OLD PDF is shown, instead of the new one. I had to delete the temporary internet files in order to see the new one.

所以,因为我不是服务于实际写入PDF一个ASPX(而我不希望保存对话框显示),而是直接链接到PDF文件,我想知道什么是最好的方式,以确保用户总是能看到最新的文件服务器,而不是一个缓存版本。

So, since I'm NOT serving an ASPX that actually writes the PDF (and I do not want the Save dialog to show), but straight linking to the PDF file, I want to know what the best way to make sure the user always sees the latest file in the server, not a cached version.

我猜添加无缓存标头是出了问题。但是,PDF请求将仍然通过HTTP处理程序,所以我想知道我是否应该创建一个特定的HTTP处理程序来截取为PDF文件要求,或者我应该这样做在IIS的水平......不过我不必然要避免缓存所有的PDF在该网站上。

I'm guessing adding no-cache headers is out of the question. But the PDF request would still go through an HTTP handler, so I'd like to know if I should create a specific HTTP handler to intercept requests for PDFs, or if i should do this at the IIS level...however I dont necessarily want to avoid caching ALL PDF's on that site.

有什么建议?在此先感谢您的帮助。

Any suggestions? Thanks in advance for the help.

推荐答案

如果您链接到PDF文档附加了一个独特的查询字符串,我相信这将prevent缓存。在蜱的时间是一个很好的使用,例如:

If your link to the pdf document had a unique querystring appended I believe that would prevent caching. Time in ticks is a good one to use, eg:

string.Format("{0}?t={1}", pdfFileUrl, DateTime.Now.Ticks);

这篇关于有ASP.NET正道/ IIS不缓存PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆