Log out functionality not working in IE

Last post 02-05-2009 1:47 PM by yasserzaid. 6 replies.

Sort Posts:

  • Log out functionality not working in IE

    01-30-2009, 11:59 PM
    • Member
      250 point Member
    • sparrow37
    • Member since 08-25-2008, 12:53 PM
    • Posts 435

    Hi All,

     I have created code on login page's submit button which saves loginStatus in session variable. After successful login, I check on master page codebehind for loginStatus Value.

    if (Session["loginStatus"] == null || Session["loginStatus"].ToString().Equals(string.Empty) || !Session["loginStatus"].ToString().Equals("Yes")){

    Response.Redirect("Login.aspx");}

    This works fine. If i try to open default,aspx without login, It redirercts me to loginpage. I have created Signout link, which redirects to logout page where I am removing session using session.abandon,session.remove etc. and redirect to login page. But If user doesnt close IE after logout, and in address bar writes address of any secure page like default.aspx, The page displays. This problem is with IE only, firefox redirects me to login page. If I close IE and then open it and enter address of any secure page, It redirects me to login page and works fine.

     Please suggest me solution for this.

    Regards,

    Asif Hameed

  • Re: Log out functionality not working in IE

    01-31-2009, 12:45 AM
    go IE tools and check for the options
    Avantha Siriwardana
    Beware of bugs in the above code; I have only proved it correct, not tried it.
    (Donald Knuth)
    http://www.linkedin.com/in/avanthasiriwardana
  • Re: Log out functionality not working in IE

    02-03-2009, 6:38 AM
    Answer

    Hi Asif Hameed,

    *Please refer to my next reply. Sorry for inconvenience*

    ------------------------------------------------------------------------------------------------

    The problem may be casued by session. When the page is closed, the Session hasn't been disposed and when the user opens the page again, the code for detecting Session["loginStatus"] considers that the user has been logged in.

    To deal with this issue, I suggest you using JavaScript function, which is fired when page unloads, to call behind code to dispose the session.

    Have a try on the test demo below. I have written some comments to it: 

    <%@  Language="C#" %>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
        
            //when page is unloading, we find the unload button and click it.
            window.onbeforeunload = function() {
                if (event.clientX > document.body.clientWidth && event.clientY < 0 || event.altKey) {
                    document.getElementById("unload").click();
                }
            }
        </script>
    
        <script runat="server">
            protected void DoUnLoad(object sender, EventArgs e)
            {
                //write some texts to do the test.
                System.IO.File.AppendAllText(Server.MapPath("unLoadTest.txt"), "page has been unload");
            }
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <%--you can set the button's display as none to hide it--%>
            <input id="unload" name="unload" runat="server" onserverclick="DoUnLoad" type="button" value="button" />
        </div>
        </form>
    </body>
    </html>
    In your case, you can replace the code of writing texts with some other code clearing the session, like this:
    Session["loginStatus"] = null;

    Best Regards
    Shengqing Yang

     

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
  • Re: Log out functionality not working in IE

    02-03-2009, 6:46 AM
    • Contributor
      7,472 point Contributor
    • manoj0682
    • Member since 10-22-2007, 11:16 AM
    • Bangalore,India
    • Posts 1,353

    add below code in your logOff.aspx

    If Not (Session Is Nothing) Then

    Session.RemoveAll()

    Session.Abandon()

    Session.Clear()

    End If

    its working for me in IE and FireFox.

     


    Manoj Karkera
    Sapient 


    Please remember to click “Mark as Answer” on the post that helps you, it will help other(s) to get there answer.
  • Re: Log out functionality not working in IE

    02-03-2009, 6:59 AM
    Answer

    sparrow37:

    But If user doesnt close IE after logout...

    Hi,

    I am afraid I have misunderstood you before if you meant doesnt close Internet Explorer. Then, the issue is caused by cache..

    Add this code to Page_Load event handler of those pages which contain sensitive information: 

    Response.AppendHeader("Cache-Control", "no-store");

    This will make pages not cached by browser and when the user visit those pages, his session will be always checked. If he has been logged out, he will not see the content of those pages.

    By the way, my previous reply handles the situation that users close the page without logging out. If you need it, you can give it a try as well. 

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
  • Re: Log out functionality not working in IE

    02-05-2009, 12:33 PM
    • Member
      250 point Member
    • sparrow37
    • Member since 08-25-2008, 12:53 PM
    • Posts 435

    Hi All-Star,

                Thank you . you solution worked for me :)

    Regards,

    Asif Hameed

  • Re: Log out functionality not working in IE

    02-05-2009, 1:47 PM
    • Star
      13,971 point Star
    • yasserzaid
    • Member since 09-22-2007, 9:10 PM
    • Egypt
    • Posts 2,597

    try this

        protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            Roles.DeleteCookie();
            Session.Clear();
        }
    Good Luck
Page 1 of 1 (7 items)