Skip to content

Instantly share code, notes, and snippets.

View leandrocustodio's full-sized avatar

Leandro Custodio leandrocustodio

  • TheoremOne
  • Brazil
View GitHub Profile
@leandrocustodio
leandrocustodio / NoCacheAttribute.cs
Created January 10, 2018 12:44
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();