Tuesday, January 27, 2009

AJAX and browser cache

When using AJAX to update a page, if the user leaves the page and comes back via the back button, the content will revert to the values the page had when it initally loaded.  To remove that behavior the following c# code will force a refresh from the server and display the page based on the latest information on the server.

Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now;
Response.Expires = 0;
Response.CacheControl = "no-cache";

No comments: