In this article I will explain with an example, how to prevent user from navigate to previous page after Logout using back button of the browser or the back option in the context menu in ASP.Net.
One cannot disable the browser back button functionality only thing that can be done is prevent them.
 
 
Disable Browser Back Button Script
The following JavaScript code snippet must be placed in the HEAD section of the Page where the User must be prevented from going back.
<script type = "text/javascript" >
   function preventBack(){window.history.forward();}
    setTimeout("preventBack()", 0);
    window.onunload=function(){null};
</script>
 
 
Disable Browser Back Button Implementation
For illustration purposes, two Pages are used Home and Logout. After logging out User is sent to Logout page and using Browser Back button he will be prevented from going back to Home page from Logout page.
Home Page
The HTML Markup of Home page consists of an HTML Anchor link to the Logout page.
The Disable Browser Back Button Script is placed in the HEAD section so that User cannot access the Home page using Browser Back button from Logout page.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Home</title>
    <script type="text/javascript">
        function preventBack() { window.history.forward(); }
        setTimeout("preventBack()", 0);
        window.onunload = function () { null };
    </script>
</head>
<body>
    <h3>Home</h3>
    <hr />
    <a href="Logout.htm">Logout</a>
</body>
</html>
 
Logout Page
The following is the HTML Markup of Logout.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Logout</title>
</head>
<body>
    <h3>Logout</h3>
</body>
</html>
 
 
Screenshots
Disable Browser Back Button after LogOut in ASP.Net using JavaScript
 
 
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.

 
 
Demo
 
 
Downloads