Login/Logout time tracking in asp.net

I have an asp.net application that is developed under the IDE of VB2003.net enterprise edition. I can track current and historical Login date/time by calling stored procedure under MSSQL2000 database from the login.aspx page. I'm having inconsistent update of logout time for the same user when the user logs out by using the "X" on the IE browser. I tried using the Global.asax and I get a timing or inconsistent updates on the logout time. Here is the code fragment in the Global.asax. Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session ends Dim Connection As New Translator Dim stconnection As String Dim sqlLogin As New SqlConnection Dim sqlcmd As New SqlCommand Dim sqlParam As New SqlParameter Dim LogID As Integer Application.Lock() Application("UserCt") = Application("UserCt") - 1 LogID = Application("LogID") Connection.translate() stconnection = Connection.connect sqlLogin = New SqlConnection(stconnection) sqlLogin.Open() sqlcmd = New SqlCommand("UpdLogOut", sqlLogin) sqlcmd.CommandType = CommandType.StoredProcedure sqlcmd.Parameters.Add(New SqlParameter("@LogID", SqlDbType.Int)) sqlcmd.Parameters("@LogID").Value = LogID sqlcmd.ExecuteNonQuery() sqlLogin.Close() sqlcmd.Dispose() Application.UnLock() Any suggestions or work-around?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Using the session end event you will not know for sure when the user has logged out since the session end event only fires after the user has been inactive for a certain amount of time. The default time is 20 minutes but can be changed in a number of ways. If you do not have a logout button on the site you could subtract the inactivity timeout from the current time to calculate the last time the user viewed a page but you really have no idea how long the user spent looking at the last page they requested or if they are still reading the page.

Discuss This Question: 3  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Timallard
    You can use the onunload() event and javascript on the client to set a cookie when the browser is closed. Then the next time the user logs in you get an accurate time of when they closed it. What you're getting is the session timeout, not the actual time they closed the browser but that's OK until they login again, better than nothing and you just update the value in your db when they do.
    0 pointsBadges:
  • Dilipkakadiya
    20 pointsBadges:
  • manicool
    i have asp.net form .in which i want to display last date and time when i logged..mean when i open my account .label show the date/time  i logged last time
    10 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: