繁体   English   中英

清除存储在客户端位置的ASP.net MVC 5中的outputcache

[英]Clear outputcache in ASP.net MVC 5 stored at client location

我是ASP.Net MVC 5的初学者。我已经在某些控制器操作中应用了缓存。 现在,我要执行一项操作以清除客户端缓存。 如何实现。 这是我现在所拥有的:

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

我看过的链接: ClearCache

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM