我是 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/