0

Hi all,

I am trying to write a code for logout, and I want to clear session

My code

 Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Session.Abandon()
        Response.Cookies.Add(New HttpCookie("ASP.NET_SessionId", "logAccount"))

        Response.Redirect("WebForm5.aspx")

    End Sub

and i want to disabling browser's to go back

please hellp !!!!

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by hericles
0

Hi,
Don't disable the back button. Instead you should have code in each of your pages (in the page_load) that checks if the session is current and if not redirects to the log in page (or whatever is relevant). There once a user logs out and the session is cleared, if they hit the back button they just get redirected.

0

Thanks hericles for your replay :)
I put this code in the page_Load

If String.IsNullOrEmpty(DirectCast(Session("logAccount"), String)) Then
            Response.Redirect("WebForm5.aspx")
        End If

when i hit the back button its goes back to the same page and displaying all the information and when i try to click on any button its redirect me to the login page

so the above code doesn't work till i click any button in the page or refresh the page ?!!!

0

I found this code that i can put in the top of every page but the problem is this code disable the back button in all pages even if the user still loged in

<script type="text/javascript" language="javascript">
    history.forward(1);
</script>
0

Thats strange, your session checking code should work as long as the session has been abandoned or cleared. The javascript version won't help, it is designed to simply break the back button (bad idea). debug your page and see what the value of the string is after logging out and returning to the page.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.