I created a simple ASP.NET 3.5 Web app with two pages. Each page has a label that displays the time and a Button to postback. In the Page_Load for each page I have the following:
Response.ClearHeaders();
Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1
I want to force the “page is expired” message if the user clicks on the Back button. However, what is happening is the Back button is showing the previous page, not pulling from cache but refreshing the page. The label is updated with the current time. I don’t want the page to refresh but instead show the “page is expired” message. How can I force that? I have tested this using IE9 but I need the behavior the same for all browsers.
The “page is expired” message is usually given when a browser sends a POST request to a page, and the user wishes to refresh or go back to it. To force it, you’ll have to make every page a POST request. This thread might be able to provide you with the JavaScript code to convert all links (which are GET requests) to POST requests.
Alternatively, you can use JavaScript or cookies to keep a history of the pages visited, and if the user attempts to return to a page, you can use it to redirect them or give them a message.