Accessing Public Variables from Global.asax

E

Ekul

I have an application that allows users to login and logout. I track how
many users are logged in and when each individual is logged in. The
application will not allow concurrent logins(let a user log in twice at the
same time). My problem is I am having trouble telling when the user is
logged off. If they click the logout button everything works fine. But if
the close the browser by clicking the x or navigate to another url through
the address bar I will get no indication that they have logged off. To
remedy that I placed the code to logoff the user in the Session_End method
of the Global.asax page. But there is a problem with this as well. I need
the user ID to perform the logoff tasks. I can't get this from a session
object because by the time the Session_End method is reached the session
object I previously created is destroyed. I tried using a public variable to
hold the user ID but I can not get access to it in the global.asax. I also
tried to place the user ID in a public shared variable, but this causes the
user ID to be overwritten whenever a new user logs in. Is there any way to
create a public variable that I can access from the global.asax page that is
not shared among application instances? Should I be looking at this from
another angle? Any ideas or help would be greatly appreciated.
 
G

Guest

I would create a hashtable (aka Dictionary) in application scope that tracks logins and last accessed timestamps. I would create a helper class that manages synchronizing your hashtable with objects in session. Each time Session_End is called I'd look at the hashtable and remove any old records. I'd also remove the record if the user clicks "logout". And of course, if a entry is found in the hashtable don't let the user log in. Each hashtable entry would store the login as a key and timestamp as the item

Joe Agste
www.geekyfrog.com
 
E

Ekul

Joe,

I tried something similar to this before. The only problem was that I had
know way of knowing which user was logging of when they hit Session_End.
For example, say two users logon at the same time, userA & userB. Then lets
say that userB's session times out and userA's session is still active. How
would I be able to tell it is userB that I need to logoff and not userA, or
vice versa? There is nothing that identifies who's session timed out.
Please let me know if I misunderstood your advice. Thanks for taking the
time to help!

Luke

Joe Agster said:
I would create a hashtable (aka Dictionary) in application scope that
tracks logins and last accessed timestamps. I would create a helper class
that manages synchronizing your hashtable with objects in session. Each time
Session_End is called I'd look at the hashtable and remove any old records.
I'd also remove the record if the user clicks "logout". And of course, if a
entry is found in the hashtable don't let the user log in. Each hashtable
entry would store the login as a key and timestamp as the item.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top