Bhabani prasad Dash

Bhabani prasad Dash

  • NA
  • 244
  • 43.5k

online user total user count

May 24 2013 2:40 AM
i want online user and total visitor to my site  i take two label to show online user and total user.and write below code in global.asax
and for load .but it always show output online user 1 that is correct but total user also 1.so i want when agai i run my application it will show total user2,3,4 so on

 lbl_onlineuser.Text = Application["onlineuser"].ToString();
  lbl_totaluser.Text = Application["Totaluser"].ToString();
  void Application_Start(object sender, EventArgs e)
  {
  // Code that runs on application startup
  Application["Totaluser"] = 0;
  Application["onlineuser"] = 0;

  }
 
  void Application_End(object sender, EventArgs e)
  {
  //  Code that runs on application shutdown

  }
 
  void Application_Error(object sender, EventArgs e)
  {
  // Code that runs when an unhandled error occurs

  }

  void Session_Start(object sender, EventArgs e)
  {
  // Code that runs when a new session is started
  Session.Timeout = 20;
  Session["Start"] = "Now";
  Application.Lock();
  Application["Totaluser"] = Convert.ToInt32(Application["Totaluser"]) + 1;
  Application["onlineuser"] = Convert.ToInt32(Application["onlineuser"]) + 1;
  Application.UnLock();
 

  }

  void Session_End(object 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.Lock();
  Application["onlineuser"] = Convert.ToInt32(Application["onlineuser"]) - 1;
  Application.UnLock();

Answers (4)