How Do You Access a Session Variable?

How do you reference a session variable when you’re looping through the sessions? I’m trying to check a variable called Session.username to see if the user is already logged in on another session so I can kill the old one.

I can get the session ID with:

[code] dim sess as WebSession
for x = 0 to app.sessioncount - 1

sess = app.SessionAtIndex(x)

TextArea1.text = textarea1.text + "Session ID#" + cstr(x) + ": " + sess.Identifier

next x[/code]

But, I can’t figure out how to reference the ‘Session.username’ variable for a specific session so I can compare it to the current one.

Any clues?

You can use session instead of webSession

[code]dim sess as session
for x = 0 to app.sessioncount - 1

sess = app.SessionAtIndex(x)

TextArea1.text = textarea1.text + "Session ID#" + cstr(x) + ": " + sess.Identifier

next x[/code]

Well, I saw this in the docs:

So, to compare the username session variable from one session to another, I need to store the username in a cookie and then I can access it there?

Trying to figure out if I’m on the right track or if there is just something obvious I’m missing like:

thisUser = app.SessionAtIndex(x).username

To confirm for anyone looking for this info later, the cookies option seems to be the way to go. When the program starts up, set a cookie for the session info you want to compare. Then loop through the sessions, look at the cookies and see if a session with a different identifier has the same username.

This is the language I used to check the cookie:

Dim c as Integer = App.SessionCount-1
For x = c downto 0
sess = app.SessionAtIndex(x)
sessionUser = sess.Cookies.value(“UserLoginName”)
next x

You can use a property in your session object.

Thanks!