title: How to get the accurate total visitors count in ASP.NET
body: <p>I want to know the number of visitors online on my site. I did my research and found two solutions.</p>
  
  <p>Source: Code Project<br>
  <a href="http://www.codeproject.com/Articles/29792/Online-active-users-counter-in-ASP-NET" rel="nofollow noreferrer">Online active users counter in ASP.NET</a>  </p>
  
  <p>It is easy to setup and easy to use but it increases the user count for every Ajax request/response too. My home page alone has 12 Ajax requests(8 requests to one page and 4 requests to another page). This dramatically increases the user count.</p>
  
  <p>Source: Stack Overflow Q/A<br>
  <a href="https://stackoverflow.com/questions/2902083/count-the-no-of-visitors">Count the no of Visitors</a>
  This one works exactly the same as the previous one.</p>
  
  <p>Source: ASP.Net Forum 
  <a href="http://forums.asp.net/t/1216009.aspx/1" rel="nofollow noreferrer">How to see "who is online" using C# </a>   </p>
  
  <p>This one looks better than the previous two. Here is the detail code of this solution.</p>
  
  <pre><code>void Application_Start(object sender, EventArgs e) 
      {
          // Code that runs on application startup
          HttpContext.Current.Application["visitors_online"] = 0;
      }
  
  void Session_Start(object sender, EventArgs e) 
      {
          Session.Timeout = 20; //'20 minute timeout
          HttpContext.Current.Application.Lock();
          Application["visitors_online"] = Convert.ToInt64(HttpContext.Current.Application["visitors_online"]) + 1;
          HttpContext.Current.Application.UnLock();
      }
  
  void Session_End(object sender, EventArgs e) 
      {
          HttpContext.Current.Application.Lock();
          Application["visitors_online"] = Convert.ToInt64(HttpContext.Current.Application["visitors_online"]) - 1;
          HttpContext.Current.Application.UnLock();
      }
  </code></pre>
  
  <p>It seems to be able to ignore the increasing the count for every Ajax response but it still adds up for each page refresh or page request.</p>
  
  <p>Is there any approach to count the accurate number of online visitors in ASP.Net?</p>