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

Discussion in 'ASP .Net' started by Kim Bach Petersen, Nov 1, 2004.

  1. 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 :eek:)
     
    Kim Bach Petersen, Nov 1, 2004
    #1
    1. Advertising

  2. > 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" <> wrote in message
    news:...
    > 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 :eek:)
    >
    >
     
    Kevin Spencer, Nov 1, 2004
    #2
    1. Advertising

  3. 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 :eek:)
     
    Kim Bach Petersen, Nov 1, 2004
    #3
  4. Kim Bach Petersen

    bruce barker Guest

    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" <> wrote in message
    news:...
    > 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 :eek:)
    >
    >
     
    bruce barker, Nov 2, 2004
    #4
  5. 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" <> wrote in message
    news:#...
    > 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 :eek:)
    >
    >
     
    Kevin Spencer, Nov 2, 2004
    #5
  6. Kim Bach Petersen

    JamesJM

    Joined:
    Aug 3, 2011
    Messages:
    1
    Before you call session.Abandon save any data that you will want to access in
    Session_End in local variables then after session.Abandon you can declare session variables with the local variable values and you will be able to access them in Session_End

    JamesJM
     
    JamesJM, Aug 3, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmVsYQ==?=

    Problem with Session_End in Global.asax

    =?Utf-8?B?QmVsYQ==?=, Apr 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,586
    coollzh
    Apr 13, 2004
  2. Samuel Stanojevic
    Replies:
    1
    Views:
    981
    Samuel Stanojevic
    Sep 15, 2004
  3. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    927
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  4. =?Utf-8?B?TWFubnkgQ2hvaGFu?=

    Session_end Global.asax

    =?Utf-8?B?TWFubnkgQ2hvaGFu?=, Aug 5, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    5,356
    =?Utf-8?B?U05ldW1hbm4=?=
    Sep 9, 2005
  5. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,220
    Mark Rae
    May 23, 2006
Loading...

Share This Page