Asp.Net MVC 禁止頁面快取
阿新 • • 發佈:2019-01-31
首先定義一個過濾器
然後註冊到全域性過濾器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());
}