Results 1 to 4 of 4

Thread: Sessions variables getting lost

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Sessions variables getting lost

    Hey,
    I've spend ages looking into the problem, but I cant find it.

    This is my page code

    Code:
     Protected Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
                Dim blnLogin As Boolean
            blnLogin = Login(txtUserLogin.Text, txtPassword.Text)
    
                If blnLogin = True Then
                Session("LoggedIn") = ""
                Session("LoggedInUser") = txtUserLogin.Text
                Session("LoggedInID") = GetUserID(txtUserLogin.Text)
                    lblNotice.Text = "Login succeeded: " '& GetFriends(Session("LoggedInUser"))
                Else
                    lblNotice.Text = "User not found"
            End If
        End Sub
    
        Protected Sub btnAddToWall_Click(sender As Object, e As EventArgs) Handles btnAddToWall.Click
            MsgBox(Session("LoggedInID"))
        End Sub
    So after the user presses the Login button there should be 3 variables stored in a session, this works (checked using trace='true')

    Session State
    Session Key Type Value
    LoggedIn System.String
    LoggedInUser System.String User
    LoggedInID System.Int32 2

    That's fine. Now I click on the AddToWall button to check if I can get the LoggedInID, it shows an empty messagebox.

    In the trace there are no Sessions keys left.
    How can I make it keep the keys after postback/after clicking on buttons?

    Note: When calling GetFriends(Session("LoggedInUser")) in the same sub as the Login button the variable does get passed to the class with sub GetFriends()

    Here's my web.config
    Code:
    <?xml version="1.0"?>
    <configuration>
    
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <sessionState timeout="30" />
      </system.web>
    
    </configuration>
    Last edited by vixez; Jan 28th, 2012 at 09:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width