• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

session problem asp.net(vb lang)

helo experts..i posted a previous question but no solutions..
look i've a login form whereby administrator and customer can login. once the button login is clicked the login code is processed and session is created as preview below.

 If txtPassword.Text = p And rdr!Role = "admin" Then

                FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, chkRememberMe.Checked)
                Session("UserName") = Request("txtUsername")
                Response.Redirect("homeadmin.aspx")

            ElseIf txtPassword.Text = p And rdr!Role = "user" Then

                FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, chkRememberMe.Checked)
                Session("User") = Request("txtUsername")
                Response.Redirect("homeuser.aspx")

i works fine and direct me to the homeadmin or homecustomer page...the problem am facing is that once login, when i type login.aspx in the address bar, it brings me back to login form...which is wrong as session is already created..i tried to put the piece of code written below in Page_Load of the login page but in vain..plz help
If Session("UserName") <> "" Then
            Response.Redirect("homeadmin.aspx")
        End if
 
       If Session("User") <> "" Then
            Response.Redirect("homeuser.aspx")
        End If

Open in new window

0
thomas455
Asked:
thomas455
1 Solution
 
amanolaCommented:
Session("UserName") refers to the Session, while "" refers to a string value. If you want to reference the Session try:
If (Not (Session("UserName")) Is Nothing) Then
            Response.Redirect("homeadmin.aspx")
        End if
 
       If Not (Session("User")) Is Nothing) Then
            Response.Redirect("homeuser.aspx")
        End If

If you want to referrence the value of the Session string as "" try:
If (Session("UserName").ToString <> "") Then
            Response.Redirect("homeadmin.aspx")
        End if
 
       If (Session("User").ToString <> "") Then
            Response.Redirect("homeuser.aspx")
        End If
0
 
neo00000110Commented:
Hi,

I've just got the forms authentication method set in web.config, and run this piece of code to keep the session logged in:

 FormsAuthentication.SetAuthCookie(objSqlRS.Item("Myuser_ID"), True)
response.redirect("redirecturl")

does it not work this way for you?
0
 
thomas455Author Commented:
thanks it was a problem with the brackets...it worked.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now