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

by Vignesh 10/1/2008 6:53:26 AM

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

Search


Tags



Categories

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

All Items
Sign in

Disclaimer

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

Powered by BlogEngine.NET 1.4.5.0