Click here to Skip to main content
16,019,976 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
when loging out how can i disable the go back button of browser..now when i click on the log out button in my project i redirect to log in page but the go back is still enabled and so no use...how can i solve this..
Posted
Updated 21-Mar-18 17:21pm

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:
C#
// Code disables caching by browser. Hence the back browser button
// grayed out and could not causes the Page_Load event to fire 
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();

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>
 
Share this answer
 
Comments
Rajesh Sajjanar 5-Sep-10 14:11pm    
Reason for my vote of 1
User is asking how to disable the browser backbutton while logging out, claering session and cache is not the answer
version_2.0 8-Jun-11 7:10am    
You are correct...

See my link..
You can remove the session by using :

Session.Remove("SessionName");


Anurag
 
Share this answer
 
Why do you need to disable the back button? If you have properly logged the user out then pressing the back button should always return them to the login page since they're session is no longer valid.
 
Share this answer
 
Comments
danilmanuel 4-Sep-10 11:49am    
hello..how can i disable the session..
[no name] 4-Sep-10 13:50pm    
You should spend some time reading up on ASP.NET authentication
This is s common question that everybody asks the same.

I think you dont need to work with back button as browser does not allow you to handle back button.

Rather on every request you check for a session value.

Like :

if(Session["authkey"] == null)
  Response.Redirect("Login.aspx");


This will ensure that when any link is clicked after log out, it automatically redirects to Login page.

Other than that you can also put a forward javascript to ensure that you disable browser back.

Check this :
http://csharpdotnetfreak.blogspot.com/2009/04/disable-browser-back-button-javascript.htm[^]
 
Share this answer
 
try this...


when you log out just give a message box that you are logging out.... and then redirect to login page:

like this:

Response.Write("<script>alert('you are logging out..... .......');window.location = 'loginPage.aspx'</script>");
 
Share this answer
 
You need to disable the back button after the user signout the account...

I think This will help you[^]
 
Share this answer
 
Hi

Try adding the following code to your homapage Page_load
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetNoStore();


Thanks.
 
Share this answer
 
v2
Comments
RaviRanjanKr 8-Jun-11 6:42am    
Always Wrap your code in "pre" tags :)
Dylan Morley 8-Jun-11 6:44am    
And don't bump old threads with answers that are exactly the same as other peoples. How is this different from S Mewara's answer?
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
 
Hope this[^] might help you.
 
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