Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am disable back button after logout but it not working. i am using master page for my login page. i implement this code in my dashboard master page where i place my logout button.


C#
if (!IsPostBack)
           {
               Response.Buffer = true;
               Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
               Response.Expires = -1500;
               Response.CacheControl = "no-cache";
               Response.Cache.SetNoStore();
               if (Session[SessionKeys.CurrentUser] == null)
               {
                   Response.Redirect("Default.aspx");
               }
           }
Posted

JavaScript
<script type="text/javascript" language="javascript">
function DisableBackButton() {
window.history.forward()
}
DisableBackButton();
window.onload = DisableBackButton;
window.onpageshow = function(evt) { if (evt.persisted) DisableBackButton() }
window.onunload = function() { void (0) }
</script>

We need to place above script in header section of a page wherever we need to prevent users navigate back to another page by using browser back button.
 
Share this answer
 
v3
Comments
Manohar Khillare 19-Aug-13 6:27am    
where this script need to be added
Please go through the awesome Tip - Browser back button issue after logout[^] to know different techniques to handle this issue.
 
Share this answer
 
Use the below code on the page(head) which you want to prevent to be landed using back button.
C#
<script type="text/javascript">
  function preventBack() { window.history.forward(); }
  setTimeout("preventBack()", 0);
  window.onunload = function() { null };
</script>
 
<script language="JavaScript" type="text/javascript">
  javascript: window.history.forward(1);
</script>

You are done.

Regards..:)
 
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