locked
How to get the current date time when a session ends RRS feed

  • Question

  • User1893413161 posted

    I want the current date time added to my database when the user exits out of the website. I'm guessing the session ends when they exit out? How do I do this?

    Sunday, November 25, 2012 8:43 PM

Answers

  • User-236004499 posted

    Hi,

    Seession time out apply only when user has logged into the website. To record datetime into the database add your DB update code into the Global.ascx page in the "Session_End" event

    void Session_End(object sender, EventArgs e)
            {
                // Code that runs when a session ends. 
                // Note: The Session_End event is raised only when the sessionstate mode
                // is set to InProc in the Web.config file. If session mode is set to StateServer 
                // or SQLServer, the event is not raised.
    
            }

    Alternatively, you can setup Session time out page / login time out page (TimeOut.aspx) into the WebConfig file and on the pageload event of TimeOut.aspx page run your DB code to record date and time.

    <authentication mode="Forms">
          <forms  loginUrl="Timeout.aspx"  timeout="20" />
        </authentication>

    Regards,

    Pratik

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 26, 2012 3:22 PM

All replies

  • User1779161005 posted

    Well, depends. Do you mean session state, login session or they just are done with your app and close the browser?

    Sunday, November 25, 2012 9:22 PM
  • User1893413161 posted

    Just done and close the browser

    Monday, November 26, 2012 9:57 AM
  • User1779161005 posted

    This is a very hard problem to solve. I don't have a failsafe solution for you.

    Monday, November 26, 2012 10:28 AM
  • User-236004499 posted

    Hi,

    Seession time out apply only when user has logged into the website. To record datetime into the database add your DB update code into the Global.ascx page in the "Session_End" event

    void Session_End(object sender, EventArgs e)
            {
                // Code that runs when a session ends. 
                // Note: The Session_End event is raised only when the sessionstate mode
                // is set to InProc in the Web.config file. If session mode is set to StateServer 
                // or SQLServer, the event is not raised.
    
            }

    Alternatively, you can setup Session time out page / login time out page (TimeOut.aspx) into the WebConfig file and on the pageload event of TimeOut.aspx page run your DB code to record date and time.

    <authentication mode="Forms">
          <forms  loginUrl="Timeout.aspx"  timeout="20" />
        </authentication>

    Regards,

    Pratik

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 26, 2012 3:22 PM