Skip to content

Instantly share code, notes, and snippets.

@leandrocustodio
Created January 10, 2018 12:44
Show Gist options
  • Save leandrocustodio/d48ba7423b6bbed18c51fd14c565b9c4 to your computer and use it in GitHub Desktop.
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
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