Results 1 to 11 of 11

Thread: Currently Logged In Users ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    Currently Logged In Users ?

    I have created a small web-application.
    It starts with a login screen.

    Everybody who log in should see a list of users currently logged in. While logging In I update the LoggedIn flag to True and make it False while logging Out.

    But if the user simply closes the browser without clicking Log-Off button then the LoggedIn flag remains True showing him as still Logged in to other users.

    How to tackle this problem ?
    Last edited by anis_b; Mar 30th, 2004 at 05:34 AM.
    Anis Bombaywala

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Use the Page_Unload event.

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Wey_97: If you may,. I just want to clear up the confusion you may have had.

    The page_unload event is part of the page lifecycle on the server. In other words, it always fires, anytime the server builds a response to a client action. After the response has been built, the ASP.NET framework disposes of the class which represents the page to free resources. After (some may argue, while) its been unloaded, the server response to client request is sent.

    The UnLoad event is for closing down database connections, or disposing of resources that consume system services.

    It DOES NOT fire when a client closes his browser window, or navigates to another page.

    In regards to the author's question, you should make use of Forms Authentication, which takes care of these issues for you.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    Can you pls clarify the solution you gave ?

    You mentioned something about Forms Auth.

    Will that solve my prob ?

    even tried the "Application_End" & "Session_End" events.

    But what if the user directly closes his browser window.

    Actually my requriement is that other users who are currently logged in should have a clear picture of who else are logged in.

    Right now what is happening is that if the user simply closes his browser window he shows logged in for others.

    Something like an hidden iframe which constantly montiors at regular intervals who all are logged in will also do.
    Anis Bombaywala

  5. #5
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378
    Use session Ids in session variables for each user when they login the website; assume that after X minutes of inactivity the user has probably left the site. So when your session variables expire this would probably mean that this user has left the site. You wont be able to exactly know the time at which users have left the site without clicking on logout. Can't think of a better solution for now, will get back to this if I find another alternative.
    >!v!<
    Free your mind, stop thinking
    http://inspirone.blogspot.com

    Please rate this post if it helped you

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    confused... !!

    when the user logs in I update the field LoggedIn = 1 and when he logs out or closes the window then that field needs to be = 0.

    from where do i test whether that session has expired or not ?
    Anis Bombaywala

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, ya don't test, Sessions expire 20 minutes by default.

    Session_End is in your Global ASAX file. There's an event in there, if you put code in, that code will execute everytime a session ends.

    So if someone logs in (remember, you have to log in at vbforums too), you add them to a table of logged in users.

    In your Session_End event, you put the code that removes them from the table. Session_End will fire either when they have had no activity with the server for 20 mins( 20 mins is the default), or they explicitiy hit LOG OUT.

    If your session is saved with StateServer and/or SQL Server persistence, the Session_End event in Global is never fired. Only InProc mode fires this. But InProc is the default, so unless you changed it, you should be ok.
    Last edited by nemaroller; Apr 2nd, 2004 at 08:00 AM.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    will the Session_End event fire when...

    the user simply closes the browser window ?

    this is the major problem..
    i am already logging him out on click of Log Off button
    Anis Bombaywala

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    There are two solutions:

    One, which everyone seems to believe is ok, including me, is just set the session expiration to 10 minutes. Once the session expires, they no longer show up in your table of logged in users, because on the session_end event, you remove them from that data table.

    Two, you could, throw some Javascript in the form unload, that would connect back to your server, and remove the user. However, obviously, if JS is not enabled, this won't work (but then you would have the session_end event to eventually catch that in 10 or 20 minutes). Also, I believe Opera browsers don't fire the unload event when the browser is closed.

    Additionally, you will find Unload fires anytime the user navigates somewhere (even at your site). Because it is actually tied to the HTML Document being unloaded, not the browser itself.

    However, there are some ways to distinguish between those scenarios.


    http://www.faqts.com/knowledge_base/...d/17816/fid/53


    Once you have that working, then you will need to use JS to communicate back to the server.

    So in a nutshell, yes it could be done, it won't be 100% reliable, it involves alot of JS programming, and could fail because of the inherint sandbox JS is based upon.

  10. #10
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    to anis_b:
    Are you updating the flag in a database, or are you using sessions? I want to solve this problem using sessions but I can't make it work. So if you're using sessions it would be great if you could post some code.

  11. #11
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    to anis_b:
    Are you updating the flag in a database, or are you using sessions? I want to solve this problem using sessions but I can't make it work. So if you're using sessions it would be great if you could post some code.

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