Link to home
Start Free TrialLog in
Avatar of TUS11
TUS11

asked on

how to expired previous page when we click on back button in asp.net

how to expired previous page when we click on back button in asp.net
Avatar of Roman Gherman
Roman Gherman
Flag of Moldova, Republic of image

You need to put nocache

------------------------
You can find me on: http://extremedev.blogspot.com
uuups,

Forgot to add the code:
<% System.Web.HttpContext.Current.Response.AddHeader( "Cache-Control","no-cache")
System.Web.HttpContext.Current.Response.Expires = 0
System.Web.HttpContext.Current.Response.Cache.SetN oStore()
System.Web.HttpContext.Current.Response.AddHeader( "Pragma", "no-cache")%>

Open in new window


Put that on the top of the aspx page or on code behind.
This will make the page not to be cached and when clicking back button in browser - it will not have anything to display except Web page expired.

------------------------
You can find me on: http://extremedev.blogspot.com
Avatar of TUS11
TUS11

ASKER

Hi,
  i add the above code on page load of the first page and when i redirect to second page from the first page then if i use the back button  on second page then it does not expired page message. it show the first page.


Please help me bcoz it is urgent for me.


Thanks
Avatar of Todd Gerbert
Setting these seems to work in a quick test for me:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

Open in new window


Keep in mind, though, that ultimately it's up to the web browser and there is no guarantee that the browser will honor the cache control headers.
OK,

It looks like this only works if the connection is secure: https.

Otherwise you will have to use session variables and when navigate away then delete the variable from the session.

In codebehind check if page had "expired" - using the Session Variable then Redirect to a Web Page Expired page (a simple html page which you will have to create).

You will also set this:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

Open in new window

In order for page to make a postback when you click back button, so that you will be able to do your check on codebehind.

------------------------
You can find me on: http://extremedev.blogspot.com
Avatar of TUS11

ASKER

Hi,

All above solution not working for me.
we are using http not https then in this case what i do for expiring the page.
Please help me.

Thanks
What browser are you using, which version of the .Net Framework, what code in your ASPX page, and how are you determining that the page is still being cached?
Avatar of TUS11

ASKER

hi,
    I am using IE8, 2.0 .net framework.
    and in code behind of ASPX page i am using this below code on page load.
System.Web.HttpContext.Current.Response.AddHeader( "Cache-Control","no-cache")
System.Web.HttpContext.Current.Response.Expires = 0
System.Web.HttpContext.Current.Response.Cache.SetN oStore()
System.Web.HttpContext.Current.Response.AddHeader( "Pragma", "no-cache")

For checking the page expiry i have the two page.
On first page i have a button which id redirected to the second page but i want that when we press BACK button then first page should be show the Page Expiry warning message.
and the above code i add on the first page .


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TUS11

ASKER

Please cancel this request
Avatar of TUS11

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for TUS11's comment http:/Q_26897839.html#35189676

for the following reason:

OK solution
I think http:Q_26897839.html#a35195100 adequately demonstrates how to force a page to expire, complete with code and a screencast.