how come i never pass through Session_End(..) in global.asax

Discussion in 'ASP .Net' started by Franck, Oct 5, 2005.

  1. Franck

    Franck Guest

    Hello,
    I'm trying to count the number of current user that way


    public class Global : System.Web.HttpApplication
    {
    public static int nbUsers;
    protected void Application_Start(Object sender, EventArgs e)
    {
    nbUsers = 0;
    }
    protected void Session_Start(Object sender, EventArgs e)
    {
    nbUsers++ ;
    }
    protected void Session_End(Object sender, EventArgs e)
    {
    nbUsers-- ;
    }
    ....
    }
    }

    but i never pass through the Session_End event
    even if I call
    Session.Abandon();

    Am i Missing anything?
    Franck, Oct 5, 2005
    #1
    1. Advertising

  2. Franck

    Brock Allen Guest

    If you're saving Session out of proc (NT State Server or SqlServer) is won't
    get called. Also, you should use Interlocked.Increment and Interlocked.Decrement
    to modify the nbUsers in a thread-safe manner. As it stands now you're code
    is not thread safe.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > Hello,
    > I'm trying to count the number of current user that way
    > public class Global : System.Web.HttpApplication
    > {
    > public static int nbUsers;
    > protected void Application_Start(Object sender, EventArgs e)
    > {
    > nbUsers = 0;
    > }
    > protected void Session_Start(Object sender, EventArgs e)
    > {
    > nbUsers++ ;
    > }
    > protected void Session_End(Object sender, EventArgs e)
    > {
    > nbUsers-- ;
    > }
    > ...
    > }
    > }
    > but i never pass through the Session_End event
    > even if I call
    > Session.Abandon();
    > Am i Missing anything?
    >
    Brock Allen, Oct 5, 2005
    #2
    1. Advertising

  3. Franck

    Franck Guest

    Thank you for your advice
    but i'm not saving the session out of proc?


    Brock Allen wrote:
    > If you're saving Session out of proc (NT State Server or SqlServer) is
    > won't get called. Also, you should use Interlocked.Increment and
    > Interlocked.Decrement to modify the nbUsers in a thread-safe manner. As
    > it stands now you're code is not thread safe.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >> Hello,
    >> I'm trying to count the number of current user that way
    >> public class Global : System.Web.HttpApplication
    >> {
    >> public static int nbUsers;
    >> protected void Application_Start(Object sender, EventArgs e)
    >> {
    >> nbUsers = 0;
    >> }
    >> protected void Session_Start(Object sender, EventArgs e)
    >> {
    >> nbUsers++ ;
    >> }
    >> protected void Session_End(Object sender, EventArgs e)
    >> {
    >> nbUsers-- ;
    >> }
    >> ...
    >> }
    >> }
    >> but i never pass through the Session_End event
    >> even if I call
    >> Session.Abandon();
    >> Am i Missing anything?
    >>

    >
    >
    Franck, Oct 5, 2005
    #3
  4. The default session timeout is 20 minutes. The web server has no way of
    knowing when a client disconnects. So the event will only be fired when the
    timeout is reached which is 20 minutes after the server was last connected
    to by the client. Have you reset the timeout so it will fire while you're
    still debugging?

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Franck" <> wrote in message
    news:di0lar$pkm$...
    > Thank you for your advice
    > but i'm not saving the session out of proc?
    >
    >
    > Brock Allen wrote:
    >> If you're saving Session out of proc (NT State Server or SqlServer) is
    >> won't get called. Also, you should use Interlocked.Increment and
    >> Interlocked.Decrement to modify the nbUsers in a thread-safe manner. As
    >> it stands now you're code is not thread safe.
    >>
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>
    >>> Hello,
    >>> I'm trying to count the number of current user that way
    >>> public class Global : System.Web.HttpApplication
    >>> {
    >>> public static int nbUsers;
    >>> protected void Application_Start(Object sender, EventArgs e)
    >>> {
    >>> nbUsers = 0;
    >>> }
    >>> protected void Session_Start(Object sender, EventArgs e)
    >>> {
    >>> nbUsers++ ;
    >>> }
    >>> protected void Session_End(Object sender, EventArgs e)
    >>> {
    >>> nbUsers-- ;
    >>> }
    >>> ...
    >>> }
    >>> }
    >>> but i never pass through the Session_End event
    >>> even if I call
    >>> Session.Abandon();
    >>> Am i Missing anything?
    >>>

    >>
    S. Justin Gengo, Oct 5, 2005
    #4
  5. Franck

    Franck Guest

    Isn't it the job of the Session.abandon();
    method?

    S. Justin Gengo wrote:
    > The default session timeout is 20 minutes. The web server has no way of
    > knowing when a client disconnects. So the event will only be fired when the
    > timeout is reached which is 20 minutes after the server was last connected
    > to by the client. Have you reset the timeout so it will fire while you're
    > still debugging?
    >
    Franck, Oct 5, 2005
    #5
  6. Franck,

    Session.Abandon is a method you can call to cause a session to end. After
    calling Session.Abandon the Session_End event will be fired.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Franck" <> wrote in message
    news:di0m5n$q8p$...
    > Isn't it the job of the Session.abandon();
    > method?
    >
    > S. Justin Gengo wrote:
    >> The default session timeout is 20 minutes. The web server has no way of
    >> knowing when a client disconnects. So the event will only be fired when
    >> the timeout is reached which is 20 minutes after the server was last
    >> connected to by the client. Have you reset the timeout so it will fire
    >> while you're still debugging?
    >>
    S. Justin Gengo, Oct 5, 2005
    #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,529
    coollzh
    Apr 13, 2004
  2. Samuel Stanojevic
    Replies:
    1
    Views:
    930
    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:
    786
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  4. Kim Bach Petersen
    Replies:
    5
    Views:
    15,702
    JamesJM
    Aug 3, 2011
  5. Mark Rae

    Global.asax / Global.asax.cs in v2

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

Share This Page