Ran

Ran

  • NA
  • 22
  • 24.5k

How to create a safe logout?

May 23 2011 7:55 AM
Hi All,
I developed a login page and added a link button(for logout) in other pages.
The code that I used behind logout is just Response.Redirect("Login.aspx")
So, when I click logout, it redirects me to the Login page but when I click back button in the browser, it goes into the application without the need of login. :-(
Can anyone please help me how to do a safe logout in a web appliction so that even when I click back button it should not be entered into the application again without a proper login?
I've uploaded the code that I used in my login page. Please refer that.
I haven't used FormsAuthentication.
Please help me to resove this in vb.net.
Imports System.Data.SqlClient

Partial Class Default2
    Inherits System.Web.UI.Page
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        Dim authentication As Boolean = False
        authentication = Sitelevelauthentication(Login1.UserName, Login1.Password)
        e.Authenticated = authentication
        If authentication = True Then
            Response.Redirect("Default.aspx")
        End If

    End Sub
    Private Function Sitelevelauthentication(ByVal Username As String, ByVal Password As String) As Boolean
        Dim boolretval As Boolean
        Dim con As New SqlConnection
        Dim Dr As SqlDataReader
        Dim sql As String
        con.ConnectionString = "Data Source=;Initial Catalog=;User ID=;Password="
        sql = "SELECT * FROM Login"
        con.Open()
        Dim cmd As New SqlCommand(sql, con)
        Dr = cmd.ExecuteReader()
        While Dr.Read()
            If Username = Dr("Username").ToString And Password = Dr("Password") Then
                boolretval = True
            End If
            Dr.Close()
            Return boolretval

        End While
    End Function
End Class

Attachment: logincode.zip

Answers (17)