model-view-controllercachingbrowser-cacheoutputcacheoutput-caching

Disable cache for aspnet mvc2 site


I have a site written using MVC2 + Entity2Sql as DB backend. I'm using jQuery dialog to edit records and populate it using action returning PartialView, but after 1st call this action returns view with old data with HTTP answer 304 Not Modified.

I checked logs - data from DB retrieved correctly, so problem with cache on client side - after clearing cache data received ok.

I performed following actions to disable cache but with no success:

Added following code to web.config, disable on server side:

<caching>
  <outputCache enableOutputCache="false" enableFragmentCache="false" />
</caching>

Added code to Site.Master, disable on client:

<meta http-equiv="expires" content="-1" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />

Added attribute to method which returs PartialContent result, same as 1st - server side:

[OutputCache(Duration = 0)]

Added "*" extension with 'Dont cache' in IIS output cache setting for my application (using IIS7)

All these methods not working for me, devtools for IE still shows that answer not 200, but 304.


Solution

  • Try:

    [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
    

    For me it works.