2014-10-30 45 views
0

如何使用iframe動態地打開多個pdf文件(根據客戶端點擊的內容一次一個),但不會將它們緩存在客戶機上,因爲如果服務器上的文件內容得到改變(增加了新的網頁,以它爲例),客戶端將仍然得到舊版本,除非他/她清除瀏覽器的緩存文件iframe緩存的PDF

回答

2

如果您使用唯一的查詢字符串參數將pdf後綴添加到PDF文件,那麼只要更改了pdf文件就會更改,瀏覽器將緩存每個版本的文件分別

例子:

變化http://site/myFile.pdf

http://site/myFile.pdf?v=f955b055-d551-4762-8313-a2417dc70568

+0

+1,儘管我發現瀏覽器在CSS的情況下忽略了這一點,但這與主題無關,只是很有趣注意。 – 2014-10-30 08:29:13

2

添加頁眉的響應,以避免donwstream服務器緩存

HttpContext.Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. 
HttpContext.Response.AppendHeader("Pragma", "no-cache"); 
HttpContext.Response.AppendHeader("Expires", "0"); 
1

你需要禁用響應cacheing的文件。在ASP.NET MVC的情況下,它就像下面這樣簡單:

[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] // will be applied to all actions in Controller, unless those actions override with their own decoration 
    public class FilesController : Controller 
    { 
     public ActionResult GetFile(string id) 
     { 
      return File();//do file 
     } 
    }