google-site-verification=ECX1M6_Vb39ty4VtQDXQce6wOjmPTxSettd3hTIZb9Q

How to Disable Back Button for Web Page? - Handling Logout Issue

random

How to Disable Back Button for Web Page? - Handling Logout Issue

javascript - Disable browser "back" button


I am facing issue in my application's logout scenario. After the user login into website and then do logout, which leads back to login page. But the problem is now, from this login page, If I click the browser back button then It again takes the user back to the previous visited page as if logged in.


disable back button, java script in browser,logout,logout button,issue, an example

Actually the back button works by stepping through the history of HTTP requests which is maintained by the browser itself. This history is stored in browsers cache that consists of the entire page content with resources like image and scripts. 

This enables browser to navigate backwards and forwards through the browser history and have each page displayed instantly from cache without the delay of having it retransmitted over the internet from the server. Find the source code below :-

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisableBackButton.aspx.cs" Inherits="DisableBackButton" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Disable Back Button for Web Page</title>

    <script type="text/javascript">window.history.forward();function noBack(){window.history.forward();}</script>

</head>
<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
    <form id="form1" runat="server">
    <div>
        Testing ..
    </div>
    </form>
</body>
</html>

  • Set Response Cache settings in code-behind file on Load for a page

      // Code disables caching by browser.
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
        Response.Cache.SetNoStore();

  • Set META tag for HTTP cache settings in your ASPX page header
    <meta http-equiv="Cache-Control" content="no-cache" />

    <meta http-equiv="Pragma" content="no-cache" />

    <meta http-equiv="Expires" content="0" />


Note:- This would not work if one disables JavaScript.

Download source code Click here ..

How to Disable Back Button for Web Page? - Handling Logout Issue Reviewed by Ravi Kumar on 7:00 PM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form

Name

Email *

Message *

Powered by Blogger.