views:

44

answers:

3

I've tried numerous ways to get IE8 to reload a page but failed. IE just keeps using it's internal cache without asking the webserver for it.

I'm sending the following headers from my webserver:

Response.Add(new StringHeader("Expires", DateTime.UtcNow.AddYears(-1).ToString("r")));
Response.Add(new StringHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"));
Response.Add(new StringHeader("Pragma", "no-cache"));
Response.Add(new StringHeader("Last-Modified", DateTime.UtcNow.ToString("r")));

It's just one of many combinations that I've tried.

How do I make IE fetch the page every time (without forcing my users to turn off caching inside IE)?

+1  A: 

The simplest way is to append a parameter with a compressed date/time stamp on the query string... This makes it looks like a whole new page to the browsers.

Just a quick update, if you are POSTing data to the server, then IE will skip the cache and load the new data. However, if you are only issuing GET requests, then IE is going to look at the URL and it's own settings to determine whether to pull from cache or actually go to the server for the data.

Now if the user has the "Check for newer versions of stored pages" set to Never, then there is nothing you can do about it short of appending a value to the query string. See KB263070 for detailed info from MS on those options. A quick look through microsoft answers shows a large number of people who have been bit by this. The solution that is always given is for the user to modify their cache settings.

So, for you, the solution is going to be to (in level of complexity)

  1. Append a highly variable query string value
  2. Inform your users that they MUST change the "Check for newer versions" setting to either Every visit to the page or Automatically.
  3. Change your links to cause post backs. (yuck)

A number of applications choose either item 2 or item 1. The reason being that 2 has the least impact on the code base while item 1 has the least impact on your users.

If this is an admin site, then I'd say go with option 2 as you should have a fair amount of leverage over the users' desktop settings.

Chris Lively
Yes, but that means that I have to modify all links on all my pages. It's an administration website where no pages should be cached (except static files)
jgauffin
A: 

Hopefully I understand your question, maybe give this a try, this will clear:

   List<string> keys = new List<string>();
    IDictionaryEnumerator enumerator = Cache.GetEnumerator();
    while (enumerator.MoveNext())
    {
        keys.Add(enumerator.Key.ToString());
    }

    foreach(string key in keys)
    {
        Cache.Remove(key);
    }

if this needs to be on multiple pages you could put it in a master page(or use some other refactoring).

There's also the OutPutCache directive, if the above isn't what you're looking for.

Chris L
No you did not. I've tried to make the problem description more clear.
jgauffin
A: 

The proper way is to send these HTTP headers in the response:

Pragma: no-cache
Expires: -1
Cache-Control: no-cache, no-store

Using them makes everything work in IE without any other modifications.

jgauffin