-1

I use this settings in my web.config file and my clients browser cached my MVC Controller Method Results? How and why? My config not target cshtml or Razor views. And what can i do now, for clear my clients browser cache?

<system.webServer>
<caching>
      <profiles>
        <add extension=".png" policy="CacheUntilChange" varyByHeaders="User-Agent" location="Client"/>
        <add extension=".gif" policy="CacheUntilChange" varyByHeaders="User-Agent" location="Client"/>
        <add extension=".jpg" policy="CacheUntilChange" varyByHeaders="User-Agent" location="Client"/>
        <add extension=".js" policy="CacheUntilChange" varyByHeaders="User-Agent" location="Client"/>
        <add extension=".css" policy="CacheUntilChange" varyByHeaders="User-Agent" location="Client"/>
      </profiles>
    </caching>
<httpProtocol allowKeepAlive="true">
      <customHeaders>
      <add name="Cache-Control" value="public, max-age=691200"/>
      </customHeaders>
</httpProtocol>

Can Ürek
  • 591
  • 11
  • 23

2 Answers2

0

You can do it programatically , try this: put this on your Model:

public class NoCache : ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext 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();

        base.OnResultExecuting(filterContext);
    }
}
and on your specific controller: e.g:

[NoCache]
[Authorize]
public ActionResult Home()
 {
     ////////...
}

Code taken From : How to clear cache in specified controller in asp mvc?

Khalil Lazhar
  • 381
  • 1
  • 12
-1

One solution would be set the version number after the .css, .js, .gif files in your project. I know this is massive changes to the system. This is how you can flush out the cache on client machines

Something like this

script.css?v=1.0 // This is the URL for release 1.0

Hope it helps. Good luck.

Cinchoo
  • 5,202
  • 2
  • 14
  • 30