Warning: Page has Expired - when users click the back button in Internet Explorer

by Vignesh 10/1/2008 2:05:26 PM

If you use the following directive

<%@ OutputCache Duration="10" VaryByParam="*" Location="Server" %>

on an .aspx page, it's possible that this can lead to an undesirable side effect when users click the back button in Internet Explorer. They will see a warning similar to

Warning: Page has Expired

The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you.

To resubmit your information and view this Web page, click the Refresh button.

It's possible to avoid this situation, if you're willing to have some additional HTTP traffic. In the ASP.NET code, add a function to handle the PreRender event, and have that emit client-side script so that IE will make a GET request to actually display the page.

For example:

private void WebForm1_PreRender(object sender, System.EventArgs e)

{

if (IsPostBack)

{

Response.Write("<html><head><script>location.replace('"+Request.Path+"');\n"+"</script></head><body></body></html>\n");

Response.End();

}

}

The result: The POST request is removed from IE's navigation history. The history will contain only GET requests. It's important to add this code in a PreRender event and not in the page load event. Otherwise the server-side events for the form itself may not be processed, and data on the server may not be updated as the user needs.

Note that this can only work in situations where the page can be properly rendered in response to a GET request.

This warning is by design in the situation where we navigate "back" to a page that was requested using POST data (the postback) and can't be retrieved from IE's cache (because of the cache-control headers).

How to prevent caching in Internet Explorer: http://support.microsoft.com/kb/234067/EN-US/

 

HTH,

Vignesh

Tags:

blog comments powered by Disqus

Comments


Disclaimer

The opinions expressed herein are our own personal opinions and do not represent our employer's view in any way.
© Copyright 2014, Rahul Soni