Skip to content

Instantly share code, notes, and snippets.

@juristr
Created December 11, 2012 07:41
Show Gist options
  • Save juristr/4256627 to your computer and use it in GitHub Desktop.
Save juristr/4256627 to your computer and use it in GitHub Desktop.
ASP.net MVC: Completely Disable Caching

This is discouraged though. You should rely on the ASP.net caching mechanisms as described in this article

public class NoCacheGlobalActionFilter : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
//IE: http://support.microsoft.com/kb/316431
if (!(filterContext.Result is FileResult))
{
HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;
cache.SetCacheability(HttpCacheability.NoCache);
}
base.OnResultExecuting(filterContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment