quarta-feira, 8 de junho de 2011

Prevent page to be cached

Who has never had a problem with the famous back button in the browser?

If you don't, so wait until the QA starts its job!!! I thought I had blocked all the leak in my system, until the QA started hitting the BACK / NEXT button in the browser and broke down everything.

To solve the problem in IE is really easy, but in Firefox can be annoying. Safari as usual, is the best one. Apple is always surprising with their usability!

Past the code bellow in the top of your Page_Load method

//Not to cache in IE
Response.Cache.SetCacheability(HttpCacheability.NoCache);
//Not to cache in Firefox
Random rd = new Random();
Response.AddHeader("ETag", rd.Next(1111111, 9999999).ToString());
Response.AddHeader("Pragma", "no-cache");
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
Response.Expires = -1;

Nenhum comentário:

Postar um comentário