前端之家收集整理的这篇文章主要介绍了
javascript – 如何在MVC应用程序中清除浏览器缓存?,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
404_0@
我想清除MVC应用程序中的浏览器缓存.
我在.cshtml页面上添加了以下代码,并且它适用于IE和Firefox.
Response.ExpiresAbsolute = DateTime.Now;
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow);
Response.Cache.SetNoStore();
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
我正在寻找一种适用于铬的解决方案.
使用以下
属性:
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
if (filterContext == null) throw new ArgumentNullException("filterContext");
var cache = GetCache(filterContext);
cache.SetExpires(DateTime.UtcNow.AddDays(-1));
cache.SetValidUntilExpires(false);
cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
cache.SetCacheability(HttpCacheability.NoCache);
cache.SetNoStore();
base.OnResultExecuting(filterContext);
}
///
}
只需将其添加到您的基本控制器:
[NoCache]
public BaseController: Controller