session problem lang)

Posted on 2009-04-23
Last Modified: 2013-12-26
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")

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

                FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, chkRememberMe.Checked)
                Session("User") = Request("txtUsername")

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


        End if

       If Session("User") <> "" Then


        End If

Open in new window

Question by:thomas455
    LVL 3

    Accepted Solution

    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
            End if
           If Not (Session("User")) Is Nothing) Then
            End If

    If you want to referrence the value of the Session string as "" try:
    If (Session("UserName").ToString <> "") Then
            End if
           If (Session("User").ToString <> "") Then
            End If
    LVL 2

    Expert Comment


    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)

    does it not work this way for you?

    Author Closing Comment

    thanks it was a problem with the worked.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now