Pages

Tuesday, January 10, 2012

To find the no.of Vistors online



Just paste the follwing code in global.asax file:

void Application_Start(object Sender, EventArgs E)
{
// Set our user count to 0 when we start the server
Application["ActiveUsers"] = 0;

}

void Session_Start(object Sender, EventArgs E)
{

Session["Start"] = DateTime.Now;
Session.Timeout = 1;
Application.Lock();
Application["ActiveUsers"] = (int)Application["ActiveUsers"] + 1;
Application.UnLock();

}

void Session_End(object Sender, EventArgs E)
{
Application.Lock();
Application["ActiveUsers"] = (int)Application["ActiveUsers"] - 1;
Application.UnLock();
Session.Clear();
Session.Remove("Start");
}



-------------in form----------
And get the Application["ActiveUsers"] where ever you need it!!!
Ex:label1.text=Application["ActiveUsers"].ToString();

No comments:

Post a Comment