By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,677 Members | 1,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,677 IT Pros & Developers. It's quick & easy.

Tracking user logins with Session_End or other

P: n/a
I would like to keep track of users when they are 'on'. On Session_Start I
can write a DB record about them, but there does not seem to be session
variable information during the Session_end event which I could use to
update the record that they are logged out. This would also be nice to limit
multiple logins.

Is there a preferred way to track users login / logout /session time and
multiple logins ?

TIA
Jun 27 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Ron J" <rj******@atsecure.netwrote in message
news:eN**************@TK2MSFTNGP03.phx.gbl...
I would like to keep track of users when they are 'on'. On Session_Start I
can write a DB record about them, but there does not seem to be session
variable information during the Session_end event which I could use to
update the record that they are logged out. This would also be nice to
limit multiple logins.

Is there a preferred way to track users login / logout /session time and
multiple logins ?

Session_End fires only when using inproc sessions.

If you're using inproc sessions, you can use Session_End to update a
database etc. When a session begins, store the userid of the user logging in
as a session variable, and it will be available to use in Session_End.

HOWEVER...

Session_End fires when the session ends. This means that you will need to
tear the session down through code i.e. by means of a "Logout" button -
otherwise, Session_End will fire when the session times out naturally, by
default after 20 minutes of inactivity. Session_End does *not* fire if the
user simply closes their browser etc...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2

P: n/a
Nice. Thanks.
What if I want to store session 'out of process' on the SQL server or State
Server?

Thanks

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:e$**************@TK2MSFTNGP05.phx.gbl...
"Ron J" <rj******@atsecure.netwrote in message
news:eN**************@TK2MSFTNGP03.phx.gbl...
>I would like to keep track of users when they are 'on'. On Session_Start
I can write a DB record about them, but there does not seem to be session
variable information during the Session_end event which I could use to
update the record that they are logged out. This would also be nice to
limit multiple logins.

Is there a preferred way to track users login / logout /session time and
multiple logins ?


Session_End fires only when using inproc sessions.

If you're using inproc sessions, you can use Session_End to update a
database etc. When a session begins, store the userid of the user logging
in as a session variable, and it will be available to use in Session_End.

HOWEVER...

Session_End fires when the session ends. This means that you will need to
tear the session down through code i.e. by means of a "Logout" button -
otherwise, Session_End will fire when the session times out naturally, by
default after 20 minutes of inactivity. Session_End does *not* fire if the
user simply closes their browser etc...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #3

P: n/a
"Ron J" <rj******@atsecure.netwrote in message
news:up*************@TK2MSFTNGP05.phx.gbl...

[top-posting corrected]
>Session_End fires only when using inproc sessions.
What if I want to store session 'out of process' on the SQL server or
State Server?
Session_End won't fire...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #4

P: n/a
Mark,
Fair enough. I'm trying to access inproc Session vars in Session_end but the
the current.Session is already null. I'm seeing some articles that say
AcquireRequestState must fire first, but not sure how to do this. Basically,
I have no access to session variable in the Session_end event. How can I
access them ?

thanks

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:e2**************@TK2MSFTNGP04.phx.gbl...
"Ron J" <rj******@atsecure.netwrote in message
news:up*************@TK2MSFTNGP05.phx.gbl...

[top-posting corrected]
>>Session_End fires only when using inproc sessions.
>What if I want to store session 'out of process' on the SQL server or
State Server?

Session_End won't fire...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #5

P: n/a
Ok, solved it. I was using something like
System.Web.HttpContext.Current.Session("name") (since there is no web
request)
This is not available in Session_End, but just
Session["name"] is.

Thanks

"Ron J" <rj******@atsecure.netwrote in message
news:ut**************@TK2MSFTNGP04.phx.gbl...
Mark,
Fair enough. I'm trying to access inproc Session vars in Session_end but
the the current.Session is already null. I'm seeing some articles that say
AcquireRequestState must fire first, but not sure how to do this.
Basically, I have no access to session variable in the Session_end event.
How can I access them ?

thanks

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:e2**************@TK2MSFTNGP04.phx.gbl...
>"Ron J" <rj******@atsecure.netwrote in message
news:up*************@TK2MSFTNGP05.phx.gbl...

[top-posting corrected]
>>>Session_End fires only when using inproc sessions.
>>What if I want to store session 'out of process' on the SQL server or
State Server?

Session_End won't fire...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.