Created
January 10, 2018 12:44
-
-
Save leandrocustodio/d48ba7423b6bbed18c51fd14c565b9c4 to your computer and use it in GitHub Desktop.
Avoid cache in user browser, this way when user click in back button the page will reload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NoCacheAttribute : ActionFilterAttribute | |
{ | |
public override void OnResultExecuting(ResultExecutingContext filterContext) | |
{ | |
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment