2017-05-04 111 views
2

我是ASP.Net MVC 5的初學者。我在某些控制器操作中應用了緩存。現在我想要一個操作來清除客戶端緩存。如何實現它。 這是我現在有:在ASP.net MVC 5中清除輸出緩存存儲在客戶端位置

[OutputCache(Duration = 10800, Location = OutputCacheLocation.Client)] 
public PartialViewResult Temp() 
{ 
    return PartialView("Index", data); 
} 

鏈接我看了看: ClearCache

它告訴使用的解決方案:Response.Cache.SetNoStore

但它會告訴客戶端緩存從不正確的?我迷失在這裏。請指導我。在某些情況下,我只想讓緩存清除。在其他情況下,緩存應按預期發生。

回答

0

在佈局頁面添加此meta標籤(在HTML頭):

<meta http-equiv="Cache-Control" content="no-cache" /> 
    <meta http-equiv="Pragma" content="no-cache" /> 
    <meta http-equiv="Expires" content="0" /> 

,並添加golbal.asax.cs

protected void Application_AcquireRequestState(Object sender, EventArgs e) 
     { 
      HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate"); 
      HttpContext.Current.Response.AddHeader("Pragma", "no-cache"); 
      HttpContext.Current.Response.AddHeader("Expires", "0"); 
    } 
+0

我可以這已經存儲在客戶端瀏覽器不清除緩存。 –