Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All,

I am trying to expire previous page if the back button of browser is clicked. I have tried the following steps:

Step #1
MIDL
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();


Step #2
<%@ OutputCache Duration="1" NoStore="true" VaryByParam="none" %>


Step #3
Response.Expires = -1;


Unfortunately, None of them work.

How Should I do this?

Regards
Aman
Posted
Comments
Vijay_Gurunanee 6-Jul-16 10:54am    
have you got any solution?

MSIL
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoServerCaching();
        HttpContext.Current.Response.Cache.SetNoStore();
        Session.Abandon();

and
Collapse
<script type="text/javascript" language="javascript">
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116 : // F5;
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
</script>
 
Share this answer
 
Comments
Aman4.net 8-Jun-11 7:17am    
Dear Wasif, I have inserted the above code in page_load event and script in Head tag but It did not work..
Mohd Wasif 8-Jun-11 7:20am    
Ok Dear it is running properly on my website let me check
You are doing the right things. You need to set, from my PHP experience:
Cache-Control: none
Pragma: no-cache
Expires: (a date/time in the past)
... to get browsers not to cache the page.

Note that that is not necessarily the same thing as preventing the back button working, though. You shouldn't try to do that, it is very annoying as a website user. Some browsers will not count going back as being a page refresh and therefore won't do a cache check.

Why do you want to do this? Most use cases can be solved by clearing the session on logout, which will cause all session-dependent internal pages to fail (usually by redirecting to a login page).
 
Share this answer
 
Look at this Tip/Trick.

Browser back button issue after logout[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900