Active User count in ASP .Net/C# application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tim007
    New Member
    • Feb 2008
    • 29

    Active User count in ASP .Net/C# application

    Hi,

    How can we get tthe number of active users connected to our web application.


    I have added application varible that gets incrimeted at session_start and then is decreased at session_end


    void Session_Start(o bject sender, EventArgs e)
    {
    // Code that runs when a new session is started

    Application.Loc k();
    Application["TotalUsers "] = Convert.ToInt32 ( Application["TotalUsers "].ToString()) + 1;
    Application.UnL ock();


    }

    void Session_End(obj ect sender, EventArgs e)
    {
    // Code that runs when a session ends.
    // Note: The Session_End event is raised only when the sessionstate mode
    // is set to InProc in the Web.config file. If session mode is set to StateServer
    // or SQLServer, the event is not raised.

    Application.Loc k();
    Application["TotalUsers "] = Convert.ToInt32 (Application["TotalUsers "].ToString()) - 1;
    Application.UnL ock();

    }

    but the count keeps on increasing ...

    i get the total users but not the total ACTIVE USERS


    thanks
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    This problem is coming may be because your session_end procedure is not getting called. So if you want to execute the code in session_end procedure then you have to call Session.Abandon () method when user Logs out from the web application.

    Originally posted by tim007
    Hi,

    How can we get tthe number of active users connected to our web application.


    I have added application varible that gets incrimeted at session_start and then is decreased at session_end


    void Session_Start(o bject sender, EventArgs e)
    {
    // Code that runs when a new session is started

    Application.Loc k();
    Application["TotalUsers "] = Convert.ToInt32 ( Application["TotalUsers "].ToString()) + 1;
    Application.UnL ock();


    }

    void Session_End(obj ect sender, EventArgs e)
    {
    // Code that runs when a session ends.
    // Note: The Session_End event is raised only when the sessionstate mode
    // is set to InProc in the Web.config file. If session mode is set to StateServer
    // or SQLServer, the event is not raised.

    Application.Loc k();
    Application["TotalUsers "] = Convert.ToInt32 (Application["TotalUsers "].ToString()) - 1;
    Application.UnL ock();

    }

    but the count keeps on increasing ...

    i get the total users but not the total ACTIVE USERS


    thanks

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by shweta123
      Hi,

      This problem is coming may be because your session_end procedure is not getting called. So if you want to execute the code in session_end procedure then you have to call Session.Abandon () method when user Logs out from the web application.
      Also, please note that the Session_End is only called if you are using InProc Session....

      -Frinny

      Comment

      • tim007
        New Member
        • Feb 2008
        • 29

        #4
        But this is not fired if the user just closes the browser ... session_end is not called when the user just closes the browser.

        if 5 users are connected and two of them just close the browsers

        the Count would still be 5 where as it should have been 3...

        we wont get the correct count of connected users

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Originally posted by tim007
          But this is not fired if the user just closes the browser ... session_end is not called when the user just closes the browser.
          Then you will have to detect when the browser is closing.
          There have been a number of threads here discussing how to do that.

          Comment

          Working...