Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
After Logout if we click on the back button of the browser it should not go back it should be in login page only.
Posted

 
Share this answer
 
Comments
thatraja 15-Nov-11 4:44am    
You beat me to it man, 5!
paste the following code on your Login.aspx. under <Head> section

XML
<script language="JavaScript">
  javascript:window.history.forward(1);
</script>

Note: above code will works only in IE

but in my view. You need to think again for your application logic so that it doesn't matter if the user presses the back button.

On you main menu screen (the page after login screen) load event, check if the Session["UserName"] == null if yes then show error message "You have logged out, please login again."

when you click on logOut call Session.Abandon(); which will clear all your session variables. and when you click on back button it will through you message "You have logged out, please login again"

it Smoothen your flow and browser independent.
 
Share this answer
 
v2
Try this javascript code in the login page, if it redirects to login page after logout:

XML
<script type="text/javascript">
    function noBack() { window.history.forward(); }
    noBack();
    window.onload = noBack;
    window.onpageshow = function (evt) { if (evt.persisted) noBack(); }
    window.onunload = function () { void (0); }
</script>
 
Share this answer
 
Comments
Member 12953984 20-Jan-17 5:01am    
it is working Thanks

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