locked
Session end fire when we manage session in sql server RRS feed

  • Question

  • User88744855 posted

    guide me what happen for session end event when session is managed in sql server?

    i want to write log to file when session end happen for a each logged in user. so guide me how to do it when session is managed in sql server? thanks

    Saturday, January 24, 2015 11:57 AM

Answers

  • User1759999623 posted

    The reason for using Session_OnEnd is because you would have your session data in memory and it would not to be cleaned up.  Session_OnEnd is used by the web server to ensure that the session memory is deleted; otherwise, you would have memory orphaned on the system, thus introducing a memory leak condition that may lead to the system running out of memory and crashing.

    With the SQL Server option, there is no need to remove session memory from the system because there isn't any.  Session_Start is used to create the SQL Server entry, but since SQL Server will handle the session data, Session_OnEnd is no longer needed and is not used.

    So, I'm not sure if there is a definitive way to determine when the session actually expired, except for creating a custom session-state mode.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 27, 2015 6:15 PM

All replies

  • User1759999623 posted

    It doesn't.  The SessionEnd is designed not to fire when using either StateServer or SQLServer modes.

    Look here for an alternative: http://forums.asp.net/t/1347992.aspx?Session+end+event+for+StateServer+SQLServer

    Saturday, January 24, 2015 12:25 PM
  • User88744855 posted

    so you means session never expire when session is managed in sql server?

    Saturday, January 24, 2015 1:19 PM
  • User-1199946673 posted

    so you means session never expire when session is managed in sql server?

    No, the session will expire, but the event Session_End doesn't fire so you can't use it.

    Saturday, January 24, 2015 2:10 PM
  • User88744855 posted

    How to detect session expire with server side code when session managed in sql server? Help me with sample code.
    Monday, January 26, 2015 5:36 AM
  • User1759999623 posted

    I think you're missing the point: When you are not using the in-process method for the session, there is no means of determining when the session expires exactly.  You could possibly run a test to see if the session has expired, but this would mean that the page is still open on the client and that you have some process testing for the session (which, of course, could end up extending the session based on how the session is supposed to expire).  As I mentioned in a previous post, I included a link so that you can review.

    Why is this necessary?

    Monday, January 26, 2015 7:52 AM
  • User88744855 posted
    It is required for my situation because i want to maintain log for session expiry. I will have a page which show data for each session expire through signalr push technology.

    is it possible to write any server side routine which detect session expiry? If u aware of such routine then please share with me.
    Tuesday, January 27, 2015 1:04 AM
  • User1759999623 posted

    The reason for using Session_OnEnd is because you would have your session data in memory and it would not to be cleaned up.  Session_OnEnd is used by the web server to ensure that the session memory is deleted; otherwise, you would have memory orphaned on the system, thus introducing a memory leak condition that may lead to the system running out of memory and crashing.

    With the SQL Server option, there is no need to remove session memory from the system because there isn't any.  Session_Start is used to create the SQL Server entry, but since SQL Server will handle the session data, Session_OnEnd is no longer needed and is not used.

    So, I'm not sure if there is a definitive way to determine when the session actually expired, except for creating a custom session-state mode.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 27, 2015 6:15 PM