For some strange reason, Firefox caches ASP.NET pages even if you tell it not to. This could create problems with the back-button. Normally you can tell the browser how to cache your web page in two ways. You can use meta tags or set some HTTP headers. To be absolutely sure that all browsers understand you cache policy, you could combine the two.

However, when you don’t want the browser to cache your page, Firefox caches it anyway. It does so because it cannot se any difference between how the page looked before and after you pressed the back-button. This issue drove me absolutely nuts today, and it took me a while to come up with a solution.

To make the back-button work with the cache in Firefox, add the ETag header to your page. Its value is a random number, and this will tell Firefox that all pages are different, even when you use the back-button to view a previously viewed page. Here’s an example that tells Firefox not to cache your page. Just add these lines to the Page_Load event:

Random rd = new Random();
Response.AddHeader("ETag", rd.Next(1111111, 9999999).ToString());
Response.AddHeader("Pragma", "no-cache");
Response.CacheControl = "no-cache";
Response.Expires = -1;

I don’t know why the ETag header is necessary in Firefox. I find it rather disturbing that the big browsers cannot agree on network issues like this.