Vivek Thakur

Chaotically Complex

  Home  |   Contact  |   Syndication    |   Login
  102 Posts | 1 Stories | 309 Comments | 73 Trackbacks

News



Archives

ASP.NET Ventures

Sometimes while clicking the Back browser button we would like the browser not to load the "cached" web page and get the fresh page from the server instead. This might be required in cases where we don't want to show user selected values in the previous page, or have some code in the previous page which we would like to run each time that page is accessed.

In ASP.NET 1.x, we can expire the response using the following code in the Page_Load():

/*
 * Code disables caching by browser. Hence hitting the back browser button* causes the Page_Load event to fire again.
 */

Response.CacheControl = "no-cache";
Response.AddHeader("Pragma","no-cache");
Response.Expires = -1;

In ASP.NET 2.0, the Expires property is deprecated (included only for backwards compatibility) and Response.Cache should be used instead. See the code below:

Response.Cache.SetExpires(DateTime.Now);
Response.Cache.SetCacheability(HttpCacheability.NoCache);

You can set it declaratively also by using the following in the ASPX page:

<%@ OutputCache Duration="0" VaryByParam="None" %>

 

posted on Thursday, December 14, 2006 11:55 AM

Feedback

# re: Expiring Response to disable Back Button functionality 12/26/2006 12:33 AM Kuldeep singh sethi
Thanks to guide me for disable back button functionality. I will practice this example on actual application and will decide it that is it helpful? and how much it is?

# re: Expiring Response to disable Back Button functionality 7/25/2007 11:58 PM se
Dammn It does not work!

# re: Expiring Response to disable Back Button functionality 2/4/2008 11:16 AM Ben
Nope - No Luck. Try again.

# re: Expiring Response to disable Back Button functionality 6/11/2008 11:14 AM abir
Thanks for provide the code it helped me lot,
this code works perfact

# re: Expiring Response to disable Back Button functionality 11/12/2008 3:43 PM Sri
The above code works fine in Internet Explorer but does not work in Mozilla firefox.

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 5 and 5 and type the answer here: