Filter NoCache
using System;
using System.Web;
using System.Web.Mvc;
namespace Site.Helpers.Filters
{
public class NoCacheAttribute : FilterBaseAttribute
{
public NoCacheAttribute()
: base(typeof(NoCacheFilter))
{
}
}
public class NoCacheFilter : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext filterContext)
{
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
var response = filterContext.HttpContext.Response;
response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
response.Cache.SetValidUntilExpires(false);
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
response.Cache.SetNoStore();
}
}
}