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

I am designing a website.Everything works fine except the logout scenario.After the user login into website,he uses it(website) and does a logout to return to Login page,but the problem is that from login page if I click the back button,again it redirects to the last used page.This should not happen.The session still exists.I used
in Logout linkbutton click event.But the problem still exists.
Is there any other solution for this and Can I use Session Timeout mechanisms.Please let me know..
Thanks and Regards,

1 solution

This happens because of cache.
1. clear the sessions
2. clear the cache such that browser has no history (this will make back/forward button in browser grayed out disabled.)

Code for clearing cache can be put up in code behind as follows:
// Code disables caching by browser. Hence the back browser button
// grayed out and could not causes the Page_Load event to fire 

You can add somethin similar in form aspx if you want to place it there:
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0"></meta></meta></meta>

You can clear browser history through JavaScript....
//clears browser history and redirects url
<SCRIPT LANGUAGE=javascript> {  var Backlen=history.length;   history.go(-Backlen);   window.location.href=page url }</SCRIPT>

OR as you say in you logout event:
protected void LogOut()   
     string nextpage = "Logoutt.aspx";       
     Response.Write("<script language=javascript>");             
     Response.Write(" var Backlen=history.length;");       
     Response.Write(" history.go(-Backlen);");       
     Response.Write(" window.location.href='" + nextpage + "'; ");
Share this answer
S.M.Naresh 18-Nov-10 0:15am    
Hi Sandeep, Your solution is very nice.But the problem here would be that the user may completely loose his browsing history(of other sites atleast),but I want to make the user go to SessionExpire Page if he clicks back button after he do logout.From there we can provide a link to Login again..How can we do this..?
thatraja 18-Nov-10 0:41am    
Excellent answer sandeep

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