失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Asp.Net MVC 禁止页面缓存

Asp.Net MVC 禁止页面缓存

时间:2023-01-10 19:17:31

相关推荐

Asp.Net MVC 禁止页面缓存

首先定义一个过滤器

public class NoCacheAttribute : ActionFilterAttribute{public override void OnResultExecuting(ResultExecutingContext filterContext){filterContext.HttpContext.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);filterContext.HttpContext.Response.Cache.SetNoStore();}}

然后注册到全局过滤器

public static void RegisterGlobalFilters(GlobalFilterCollection filters){filters.Add(new HandleErrorAttribute());filters.Add(new NoCacheAttribute());}

如果觉得《Asp.Net MVC 禁止页面缓存》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。