Results 1 to 12 of 12

Thread: Session_End not working?

  1. #1

    Thread Starter
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346

    Session_End not working?

    Does the Session_End event fire when a browser is closed? I am using Session_Start and Session_End to add and subtract from a counter. When a session starts it works fine. When a user closes the browser, the subtraction doesnt work. I am using the global.asax file to increment and decrement the count. Just that the End doesnt work. Any ideas?
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Session events (especially Session_OnEnd) have been known to be very flaky..

  3. #3

    Thread Starter
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346
    Thats what i was afraid of. Thanks!
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


  4. #4
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Flaky is a bit general. A session depends on a timeout value specified in the web.config or IIS. I think it defaults to 20 minutes. So the session will end 20 minutes after the user logs in/opens the browser regardless of when they close it.
    This is web server based technology we are talking about. I don't know any web server technology that can tell when a user closes their browser.

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Originally posted by Musician
    Flaky is a bit general.
    There are countless articles that say do not depend on the Session_OnEnd() event firing consistently.

    http://www.eggheadcafe.com/articles/20030416.asp

    http://www.mail-archive.com/bdotnet@.../msg02003.html

    etc..
    Last edited by Lethal; Nov 4th, 2003 at 10:50 PM.

  6. #6
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    I'm not disputing the unrealiability of session_onend. It's just important to be clear on why this is the case. Because of the nature of a session itself not due to any flaky design in the implementation of an event.

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I agree, because HTTP is a stateless protocol, the web server has no way of detecting when a user leaves a Web site. So, when a certain period of time has elapsed without the user requesting a page, the session data is removed and the session is killed. This is all nice an dandy, but when I say 'flaky', I am refering to the Session_End() event not *always* firing. There are numerous articles explaining workarounds because of this.

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Ya, I read those links about the session_end not working. I haven't tried to use it yet, but was looking into it to show who is currently browsing my forums. After seeing the default timeout, there is no way to accurately tell if the user is gone or not. I could adjust the timeout of the session, but it will affect other parts.

    Any suggestions on how to do this? Basically the same functionality that is on these forums to show who is browsing what forums.

  9. #9
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Hellswraith,
    I'll shoot you the code I use in my forums. What email do you want me to send it 2.

  10. #10
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    It is not that Session onend in flaky. The fact is, a web browser doesnt send a signal back to the server when it is closed. A server has no way of knowing you closed your browser.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  11. #11
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    I would imagine a non-persistent cookie is the way to go for what you want to do.

  12. #12
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Originally posted by Cander
    It is not that Session onend in flaky. The fact is, a web browser doesnt send a signal back to the server when it is closed. A server has no way of knowing you closed your browser.
    Agreed, thats what I said in my second post to clear things up.

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