Session end occurs on the server when the timeout is reached and the user may not even have their browser open when it occurs, it only fires at the end of the pipeline processing when an HTTP request has been received and a response has been rendered, that means it does NOT fire for a user who has simply closed their browser since HTTP is a stateless protocol and there is no way for the server to understand that the browser has been closed.
Also note that the session end event is only raised for InProc sessions, that means it t won't work with State Server, for example, or SQL-based session state.
Session_End event is fired by a worker process. This also means that Session_End event might not have all the permission that a normal page request has. So if you are trying to connect to the SQL server with Windows account, Session_End event might not have required permission, although you can connect to the SQL in Session_Start event.
Session_End will fire after a given amount of time where session has been inactive. The given time can be changed globally in the web.config file with the time out attribute or for individual session with the help of Session.Timeout property.
Session_End will also fire when someone calls the Session.Abondon method. Note that the Session_End event will not fire immediately. As said before the Session_End event is fired from worker process. Hence the session ID will also be same.
Server_MapPath, Request, Cache, HttpContext.Current, etc. cannot be used in the Session_End method.
© 2021 Digcode.com