Counting online users using asp.net
<p>I'm to create a website for which I need to count the online users and show it on the home page all the time. I'm not interested to apply ready-to-use modules for it. Here is what I have already done:</p>

<p>Adding a Global.asax file to my project</p>

<p>Writing the following code snippet in the Global.asax file:</p>

<pre><code>void Application_Start(object sender, EventArgs e) 
{
    Application["OnlineUsers"] = 0;
}

void Session_Start(object sender, EventArgs e) 
{
    Application.Lock();
    Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
    Application.UnLock();
}

void Session_End(object sender, EventArgs e) 
{
    Application.Lock();
    Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
    Application.UnLock();
}
</code></pre>

<p>Actually it works fine but I have found the following bug:
  --> Even if the user close the browser, the real count of online users is not shown
      since the session timeout is still alive!</p>

<p>Is there any solution but changing the session timeout interval?</p>
