You need to use Session_Start and Session_End event handlers:
public class Global : System.Web.HttpApplication
{
public static int OnlineUsers { get; set; }
void Application_Start(object sender, EventArgs e)
{
OnlineUsers = 0;
}
void Application_End(object sender, EventArgs e)
{
}
void Application_Error(object sender, EventArgs e)
{
}
void Session_Start(object sender, EventArgs e)
{
OnlineUsers++;
}
void Session_End(object sender, EventArgs e)
{
OnlineUsers--;
}
}
And your code behind:
lblOnlineUsers.Text = "Online Users: "+ Global.OnlineUsers;
Please vote if my answer will help you.