Menu ▼



Posted By :
avatarmrkraju
Total Views : 324

Disable local page caching in mvc

This example shows you how to disable the page local caching in mvc asp.net. To disable page local caching we can write the below code by overriding OnActionExecuting method in controller instead of writing in each view in controller (or you can write in a common controller and each controller will be inherited from that common controller).

protected override void OnActionExecuting(ActionExecutingContext 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();
}





comments powered by Disqus


Search dotnetlearners.com