i need to retrive some data from table registration of database to show.aspx page after login. when i register a new user after registration and redirect it to the profile.aspx page then it works fine(showing all required data). but if i do logout and again do login to the same user then the page show.aspx show nothing
I am using this code for user login:
Protected Sub btnLogin_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
Dim admin As String = "Admin"
Dim objcmd As New SqlCommand(("select * from Login where UserName='" + txtUserName1.Text & "' And Password='") + txtPassword1.Text & "'", con)
Dim objReader As SqlDataReader
con.Open()
objReader = objcmd.ExecuteReader()
If objReader.HasRows Then
While objReader.Read()
If [String].Compare(objReader("UserType").ToString(), admin) = 0 Then
Session("UserName_Admin") = txtUserName.Text.ToString().Trim()
Session("UserName") = txtUserName.Text.ToString().Trim()
Response.Redirect("adminview.aspx")
Else
Session("UserName") = txtUserName.Text.ToString().Trim()
Response.Redirect("show.aspx")
End If
End While
Else
lblLoginMessage.Text = "Login failed. Please try again"
End If
con.Close()
End Sub
code in the show.aspx page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Session("UserName") Is Nothing Then
Response.Redirect("registration.aspx")
End If
binddata()
End Sub
Sub binddata()
Dim mycommand As New SqlCommand("SELECT * FROM registration where UserName = @UserName", con)
mycommand.Parameters.AddWithValue("@UserName", Session("UserName").ToString())
con.Open()
ProfileData.DataSource = mycommand.ExecuteReader
ProfileData.DataBind()
con.Close()
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("upimg.aspx")
End Sub
i am using a datalist to retrieve data from database in show.aspx page.
is there anything i need to change in web.config file . a help will be appreciated
Is your logout code clearing the session values?
I think you would be far better off using the ASP.net Membership and Roles to handle this functionality because it will be much more secure and flexible.
Check out here an article explaining how to get setup here