public class NoCacheAttribute : System.Web.Mvc.ActionFilterAttribute { public override void OnResultExecuting(System.Web.Mvc.ResultExecutingContext filterContext) { filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false); filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); filterContext.HttpContext.Response.Cache.SetNoStore(); base.OnResultExecuting(filterContext); } }
之後在任何的Action或Class上方加上[NoCache]即可;
[NoCache] public class AController : Controller { [NoCache] public ActionResult Index() { return View(); } }
Reference:
沒有留言:
張貼留言