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

How to access session variables in Session_End in global.asax?

P: n/a
I would like to record user behavior data stored in session variables.

Since the data is modified throughout each session it seemed obvious to
store the data when the session terminates - using Session_End in
global.asax.

Problem is, apparently the session-object terminating cannot be accessed
from Session_End in global.asax!?

What's the meaning of Session_End if you don't know which session is
endning?

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Store data from
' System.Web.HttpContext.Current.Session("behavior")
' in database
End Sub

Kim :o)
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> Problem is, apparently the session-object terminating cannot be accessed
from Session_End in global.asax!?

What's the meaning of Session_End if you don't know which session is
endning?
What's the meaning of a brake pedal on a car if every car on the road has
one? The answer is, the brake pedal in the car you're driving is yours.
There is one Session per client. When Session_End is called, it is called
for that client. It is the brake pedal on that client's car. It can't
operate on any other client, any more than pressing your brake pedal can
slow down anyone else's car but yours.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Kim Bach Petersen" <ms****@kenpleasedeletesho.dk> wrote in message
news:uO*************@tk2msftngp13.phx.gbl... I would like to record user behavior data stored in session variables.

Since the data is modified throughout each session it seemed obvious to
store the data when the session terminates - using Session_End in
global.asax.

Problem is, apparently the session-object terminating cannot be accessed
from Session_End in global.asax!?

What's the meaning of Session_End if you don't know which session is
endning?

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Store data from
' System.Web.HttpContext.Current.Session("behavior")
' in database
End Sub

Kim :o)

Nov 18 '05 #2

P: n/a
Kevin Spencer skrev:
Problem is, apparently the session-object terminating cannot be
accessed from Session_End in global.asax!?

What's the meaning of Session_End if you don't know which session is
endning?


What's the meaning of a brake pedal on a car if every car on the road
has one? The answer is, the brake pedal in the car you're driving is
yours. There is one Session per client. When Session_End is called,
it is called for that client. It is the brake pedal on that client's
car. It can't operate on any other client, any more than pressing
your brake pedal can slow down anyone else's car but yours.


Clear enough, I got the concept of sessions, and of course Session_End is
called for an instance when it ends.

Still, can I access the session object from Session_End - and if yes, how?

I would like to acces session-object variables such as

System.Web.HttpContext.Current.Session.SessionId
System.Web.HttpContext.Current.Session("behavior")

but apparently I can't within Session_End?

Kim :o)
Nov 18 '05 #3

P: n/a
there is no valid System.Web.HttpContext.Current at session end because
there is no web request. just use the Session property of the global.asax

"Kim Bach Petersen" <ms****@kenpleasedeletesho.dk> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...
I would like to record user behavior data stored in session variables.

Since the data is modified throughout each session it seemed obvious to
store the data when the session terminates - using Session_End in
global.asax.

Problem is, apparently the session-object terminating cannot be accessed
from Session_End in global.asax!?

What's the meaning of Session_End if you don't know which session is
endning?

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Store data from
' System.Web.HttpContext.Current.Session("behavior")
' in database
End Sub

Kim :o)

Nov 18 '05 #4

P: n/a
You can refer to the current Session as Session or this.Session. Session is
a member of the HttpApplication class from which the Global class is
derived.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Kim Bach Petersen" <ms****@kenpleasedeletesho.dk> wrote in message
news:#w**************@tk2msftngp13.phx.gbl...
Kevin Spencer skrev:
Problem is, apparently the session-object terminating cannot be
accessed from Session_End in global.asax!?

What's the meaning of Session_End if you don't know which session is
endning?


What's the meaning of a brake pedal on a car if every car on the road
has one? The answer is, the brake pedal in the car you're driving is
yours. There is one Session per client. When Session_End is called,
it is called for that client. It is the brake pedal on that client's
car. It can't operate on any other client, any more than pressing
your brake pedal can slow down anyone else's car but yours.


Clear enough, I got the concept of sessions, and of course Session_End is
called for an instance when it ends.

Still, can I access the session object from Session_End - and if yes, how?

I would like to acces session-object variables such as

System.Web.HttpContext.Current.Session.SessionId
System.Web.HttpContext.Current.Session("behavior")

but apparently I can't within Session_End?

Kim :o)

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.