c# - 清除存储在客户端位置的 ASP.net MVC 5 中的输出缓存

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

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

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

我看的链接: ClearCache

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

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

最佳答案

在您的布局页面中添加此 meta 标记(在 html head 中):

  <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");
     }

关于c# - 清除存储在客户端位置的 ASP.net MVC 5 中的输出缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43791731/

相关文章:

c# - 使用 linq 时返回匿名类型结果

c# - 如何在.net core中使用 "System.Net.ServicePointManager"?

asp.net - MSBuild:自动收集数据库迁移脚本?

c# - MVC 模型不绑定(bind)到字典

c# - 将内存中的pdf转换为字节[]

c# - 您在参数声明中使用的 varchar(MAX) 大小是多少?

javascript - Ajax 调用中的数据长度

javascript - Bootstrap-select DropDownList 未显示

sql-server - 使用存储过程的服务器端剑道分页

c# - 如何从 Controller 方法返回多个图像?