Skip to content

Instantly share code, notes, and snippets.

@feanz
Created June 24, 2014 14:45
Show Gist options
  • Save feanz/5878289bcdab239b26a6 to your computer and use it in GitHub Desktop.
Save feanz/5878289bcdab239b26a6 to your computer and use it in GitHub Desktop.
No Cache Action filter
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
base.OnActionExecuted(actionExecutedContext);
if (actionExecutedContext.Response.IsSuccessStatusCode)
{
var cc = new System.Net.Http.Headers.CacheControlHeaderValue();
cc.NoStore = true;
cc.NoCache = true;
cc.Private = true;
cc.MaxAge = TimeSpan.Zero;
actionExecutedContext.Response.Headers.CacheControl = cc;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment