Session Length

  • Thread starter Thread starter Murray Foxcroft
  • Start date Start date
M

Murray Foxcroft

Hi all,

My client, bless his soul, wants to know how long users of his ASP.NET web
application (written by yours truly) spend logged in to the system. Now, I
can log when he logs in, no problem, but being disconnected in nature, its
hard to trap when then user effectively "closes" the session. He could click
a logout button, just close his browser or even end the IEXPLORER task from
the task manager.

Anyone done something like this before? Any special tips or tricks anyone
know of?

Thanks in advance
 
Use the Session_OnStart and Session_OnEnd events to record (1) The beginning
of the Session, and (2) the end of each Session.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Thanks for the reply Kevin, my problem being a little more tricky with an
authentication login on the site, and only authenticated sessions, per user,
must be recorded. I log the login, but associating the logout is harder,
especially in the case of a service / server restart or the like.
 
I believe that you still have the session at the Session_OnEnd event. If you
don't, then this message is meaningless.

Anyways, assuming you do, it shouldn't be too hard to check the session to
see what user it is and then log that into the database. Remember that that
means <session timeout> minutes ago, they effectively logged out of the
system.

In terms of service/server restarts, I don't know what to tell you except
that you should know when your service/server restarts. Perhaps a database
script that fills in missing values once a day with the times of
service/server restarts? Or flag those, since those are users who very
likely abruptly lost access to the site.

John Christensen
Genesee Survey Services, Inc.
 
Well, then, in the login page handler add the Session ID of the user to a
Cached Collection. In the Session_End, check the Collection for the Session
ID and if it is in the Collection, remove it from the Collection, and record
it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Back
Top