Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
How to prevent back button after logout in asp.net?
Posted 8-Jun-11 23:37pm
Comments
olegtc at 11-Apr-12 11:57am
   
Does not work in FF
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Tarun.K.S at 9-Jun-11 4:52am
   
Oh both our answers point to the same link! 5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Please use this code in your Master Page Load Event. Smile | :)
 
if(!IsPostBack)
        {
            if (Session["LoginId"] == null)
                Response.Redirect("frmLogin.aspx");
            else
            {
                Response.ClearHeaders();
                Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
                Response.AddHeader("Pragma", "no-cache");
                            }
        }
 
Ain Ronquillo
  Permalink  
v2
Comments
Silverboy with Golden Heart at 21-Mar-12 2:05am
   
its working.
Silverboy with Golden Heart at 21-Mar-12 2:06am
   
can u pls explain y v use response.addheader?
venkateshkalyani at 6-Jun-12 6:29am
   
Beauty.....
Member 9042795 at 11-Jun-12 3:06am
   
awesome...worked for me as well...
Ain Ronquillo at 23-Aug-12 2:05am
   
The AddHeader method adds a new HTML header and value to the response sent to the client. It does not replace an existing header of the same name. After a header has been added, it cannot be removed.
prabashanash at 27-Feb-14 7:41am
   
good work.. works perfectly
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use it in code behind
 
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoServerCaching();
        HttpContext.Current.Response.Cache.SetNoStore();
        Session.Abandon();
 

Use it on head tag of aspx page
 

<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>
  Permalink  
v3
Comments
Alok Kumar Sharma at 11-Jun-11 8:53am
   
Thanks
Alok Kumar Sharma
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I would like you to see this excellent tip by Sandeep : http://www.codeproject.com/Tips/135121/Browser-back-button-issue-after-logout.aspx[^]
 
Hope it helped.
  Permalink  
Comments
JustWorking at 9-Jun-11 8:42am
   
Check solution 3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Kill the session and check in each page if session is empty redirect to login page
  Permalink  
Comments
Alok Kumar Sharma at 11-Jun-11 8:26am
   
Thanks,
 
This is alternate solution.
Member 10931224 at 17-Jul-14 3:49am
   
how to check that session is empty
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

hi,,
 
best practice redirect to signout.aspx (create a new page for that) and on the page load write the code,
 
ie, clear all sessions and redirect to login page or what ever it is so when ever the person hit back button it will come to signout.aspx and redirect to login page
 

happy coding
  Permalink  
Comments
anvas kuttan at 10-Jun-11 0:08am
   
why tou down voted this one if you dnt like this answer simply reject it
JustWorking at 10-Jun-11 4:10am
   
Same for solution 3 I don't know why downvote :( I 5'ved you and I hope you do same for me :)
anvas kuttan at 10-Jun-11 4:15am
   
yes i did
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function changeHashOnLoad()
         {
            window.location.href += "#";
            setTimeout("changeHashAgain()", "50");
        }
 
        function changeHashAgain()
         {
            window.location.href += "1";
        }
 
        var storedHash = window.location.hash;
        window.setInterval(function ()
        {
            if (window.location.hash != storedHash)
             {
                window.location.hash = storedHash;
            }
        },
        50);
    </script>
</head>
<body onload="changeHashOnLoad(); ">
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>
 
rajendra patel jat
  Permalink  
Comments
Member 10236682 at 25-Feb-14 2:40am
   
too good and very absolute for requirment

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 1 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100