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

by Vignesh 9/30/2008 7:35: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



Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway. We try our best to write good code, but none of the code here is tested on Production boxes. Feel free to use the code, BUT test it before you do so (in simple words... use it at your own risk)

© Copyright 2009

Sign in