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 !!!!

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.

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 ?!!!

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>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.