2

I'm developing a dynamic web application (running on IIS7), it works fine in all the major browsers, except IE9. It seems, that it caches practically everything, and that leads to quite many problems, like

  • Often changing contents remain unchanged
  • User visits an authorized content, then signs out, then tries to go back to the secured content and gets it from cache!

I've tried disabling cache with

<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

but no luck so far...

TDaver
  • 7,024
  • 5
  • 44
  • 91

3 Answers3

3

I've just come across this in an MVC development.

I wanted to disable caching of all AJAX requests server side.

To do this I registered the following global filter.

public class AjaxCacheControlAttribute:  ActionFilterAttribute
{
    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
        if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
        {
            filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
            filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            filterContext.HttpContext.Response.Cache.SetNoStore();
        }
    }
}
ActualAl
  • 1,062
  • 10
  • 13
1

Are you making heavy use of AJAX? Make sure each AJAX request is unique, otherwise IE9 will serve up a cached version of the request response.

For example, if your AJAX request URL normally looks like: http://www.mysite.com/ajax.php?species=dog&name=fido

Instead, add a unique value to each request so IE doesn't just use the cached response. The easiest way to do that in Javascript is a variable that increments each time you make a request:

var request_id = 0;

var request_url = "http://www.mysite.com/ajax.php?species=dog&name=fido&request_id="+request_id;
request_id++;
James
  • 10,716
  • 1
  • 15
  • 19
  • 1
    If this is the prob, and they use jQuery for AJAX, this is a good global solution: http://www.peteonsoftware.com/index.php/2010/08/20/the-importance-of-jquery-ajaxsetup-cache/ – James McCormack May 12 '11 at 12:56
  • That's useful if you use Jquery, but not everyone does (I know I don't). – James May 12 '11 at 12:58
  • This was helpful: http://stackoverflow.com/questions/367786/prevent-caching-of-ajax-call – BeaverProj Jul 06 '11 at 22:24
0

Try

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

Also, required reading: http://support.microsoft.com/kb/234067

two7s_clash
  • 5,527
  • 1
  • 25
  • 44