Accessing Public Variables from Global.asax

Discussion in 'ASP .Net' started by Ekul, Jan 30, 2004.

  1. Ekul

    Ekul Guest

    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.
    Ekul, Jan 30, 2004
    #1
    1. Advertising

  2. 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
    =?Utf-8?B?Sm9lIEFnc3Rlcg==?=, Jan 30, 2004
    #2
    1. Advertising

  3. Ekul

    Ekul Guest

    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" <> wrote in message
    news:...
    > 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 Agster
    > www.geekyfrog.com
    Ekul, Jan 30, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    820
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  2. Nathan Sokalski

    Accessing variables declared in Global.asax.vb

    Nathan Sokalski, May 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    13,349
    worlebird
    Oct 17, 2006
  3. =?Utf-8?B?dnZlbms=?=

    Access to public variables defined in Global.asax.vb

    =?Utf-8?B?dnZlbms=?=, Oct 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,404
    John Smith
    Oct 10, 2005
  4. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,152
    Mark Rae
    May 23, 2006
  5. shark_bait
    Replies:
    0
    Views:
    865
    shark_bait
    Jul 17, 2006
Loading...

Share This Page