How to handle session end in global.asax?

ashish bhatt picture ashish bhatt · Mar 7, 2009 · Viewed 75k times · Source

I'm working in chat application, I used HashTable for containing User and Operator as a Key & Object of ChatRoom Class as a value of HashTable. Main problem is that When user or Operator close browser or disconnected without logout then It is automatically logout on the end of the session.

Please help me related to that and how to use Global.asax in this matter.

Answer

Canavar picture Canavar · Mar 7, 2009

You can use global.asax's session end event to remove the unexpectedly disconnected user :

void Session_End(Object sender, EventArgs E) {
    // Clean up session resources
}

but beware, session doesn't end when the user closes his browser or his connection lost. It ends when the session timeout reached.