2017-05-04 82 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

我可以这已经存储在客户端浏览器不清除缓存。 –