Right way to have ASP.NET / IIS NOT cache PDF files

后端 未结 3 1861
天命终不由人
天命终不由人 2021-01-02 06:54

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 pa

相关标签:
3条回答
  • 2021-01-02 06:57

    The fact the clearing your temporary internet files gave you the new version shows the browser is the source of the cache. You could turn iis caching off but that wouldn't stop proxies caching the document. If you need to be 100% sure that the user sees that latest version, I suggest using a query string value to cause the url to be different. The query string could be the pdf generation timestamp.

    0 讨论(0)
  • 2021-01-02 07:09

    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);
    
    0 讨论(0)
  • 2021-01-02 07:21

    I just had a similar issue. I have my page allows users to input data and generate new a pdf file Save clicked. The new pdf file overwrites the old one. In IE8, when user click the pdf link after the Save, the old pdf will always showed (user need to clear the cache to display the new one). After hours of searching, I found that in IIS6, go to 'Output Caching', add a new cache rule with file extension '.aspx', tick both 'User-mode caching' and 'Kernel-mode caching' then under both options, select 'Prevent all caching'. This is working for me!

    0 讨论(0)
提交回复
热议问题