Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote the below codes for visitors count (online users) for my application (in Global.asax)
I brows my website in some browser (IE and mozilla and chrome)
the number of users increase correctly but when I close some browsers it not decrease.

void Application_Start(object sender, EventArgs e)
  {
      Application["count"] = 0;
  }
 

  void Session_Start(object sender, EventArgs e)
  {
      Application["count"] = Convert.ToInt32(Application["count"]) + 1;
  }

  void Session_End(object sender, EventArgs e)
  {    
      Application["count"] = Convert.ToInt32(Application["count"]) - 1;
  }
Posted
Updated 1-Nov-13 4:26am
v2

You forgot to Lock & Unlock. Check this
How to show number of online users / visitors for ASP.NET website[^]
 
Share this answer
 
Comments
sahar11 1-Nov-13 11:43am    
I add lock & unlock.
and set sessionstate mode to InProc in the Web.config file.
but the result no change!
Session_End event is raised when close a browser?
thatraja 1-Nov-13 12:07pm    
No, it's when a session expires. Check this.
SessionStateModule.End Event
check this one :

http://www.aspdotnetfaq.com/Faq/How-to-show-number-of-online-users-visitors-for-ASP-NET-website.aspx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900