<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["OnlineUsers"] = 0;
}
void Application_Error(object sender, EventArgs e)
{
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs whenever a new session starts
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// This Session_End event is raised when the
//sessionstate mode
// is set to InProc in Web.config file.
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
Application.UnLock();
}
</script>
then add the following code in any page to show
how many visitors are watching your website -
Total Visitors online - <%= Application["OnlineUsers"].ToString() %>