How to get notified of session end?

前端 未结 4 1677
天命终不由人
天命终不由人 2020-12-06 20:41

I am wondering if I can handle a session timeout event. I need to make a function call to my function right before session timeouts or user left my page, or closed browser w

4条回答
  •  半阙折子戏
    2020-12-06 21:28

    The web is stateless so you're not going to know whether the user has closed the browser window. You can use the 'Session_End' event in the global.asax file for session timeouts. If you want access to all sessions, you can store them in a collection via the 'Session_Start' event, also in the global file ..

    Edit: If you want to intercept the close event of a page using javascript, here's how (note, this is unreliable):

    window.onbeforeunload = closeIt;
    
    function closeIt(){ 
    
    
      return "You have unsaved changes. Are you sure you want to leave this page?";
    
    }
    

提交回复
热议问题