andrew4582

No Cache Attribute MVC

Aug 8th, 2013
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6.  
  7. namespace Site.ActionFilters
  8. {
  9.     public class NoCacheAttribute : ActionFilterAttribute
  10.     {
  11.         public override void OnResultExecuting(ResultExecutingContext filterContext)
  12.         {
  13.             filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
  14.             filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
  15.             filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
  16.             filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  17.             filterContext.HttpContext.Response.Cache.SetNoStore();
  18.  
  19.             base.OnResultExecuting(filterContext);
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment