【问题标题】:Clear outputcache in ASP.net MVC 5 stored at client location清除存储在客户端位置的 ASP.net MVC 5 中的输出缓存
【发布时间】:2017-10-03 03:43:56
【问题描述】:

我是 ASP.Net MVC 5 的初学者。我在某些控制器操作中应用了缓存。现在我想要一个清除客户端缓存的操作。如何实现它。 这是我现在拥有的:

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

我看过的链接: ClearCache

它有一个解决方案告诉使用:Response.Cache.SetNoStore

但它会告诉客户端永远不要缓存,对吗?我在这里迷路了。请指导我。在某些情况下,我只希望缓存被清除。在其他情况下,缓存应按预期进行。

【问题讨论】:

    标签: c# asp.net asp.net-mvc caching asp.net-mvc-5


    【解决方案1】:

    在你的布局页面中添加这个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");
         }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      相关资源
      最近更新 更多