how to count number of Visitors in asp .net?
how to count number of Visitors in asp .net?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sourav mondal 0Posted Oct 25, 2013, 1:39 PM
Sunny SharmaPosted Jun 19, 2013, 3:06 AM
My suggestion is to use two variables to track counts, one for Online visitors and other for the Total.
Edit your Global.asax file for Session_Start and Session_End events as below:
----------------------------------------------------------------------------
public static int totalVisitors,onlineCounter = 0; void Session_Start(object sender, EventArgs e)
{
Application.Lock();
onlineCounter++;
totalVisitors++;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
Application.Lock();
onlineCounter--;
Application.UnLock();
}
-----------------------------------------------------------------------------
I prefer using an static variable because:-
"It is recommended that you store data in static members of the application class
instead of in the Application object. This increases performance because you can
access a static variable faster than you can access an item in the Application
dictionary." -says Microsoft (http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312607)
Hope you got the point.
Mark this as answer if it helps.
Cheers!
Pankaj PandeyPosted Jun 19, 2013, 12:41 AM
http://aspdotnetby.blogspot.in/2012/04/site-counter-in-aspnet-and-c.html
Sanjeeb LenkaPosted Jun 19, 2013, 12:22 AM
The sample code is given below:
void Application_OnStart(Object Sender, EventArgs E)
{
Application["CurrentUsers"] = 0;
}
void Session_OnStart(object Sender, EventArgs E)
{
Application.Lock();
Application["CurrentUsers"] = System.Convert.ToInt32(Application["CurrentUsers"]) + 1;
Application.UnLock();
}
void Session_OnEnd(object Sender, EventArgs E)
{
Application.Lock();
Application["CurrentUsers"] = System.Convert.ToInt32(Application["CurrentUsers"]) - 1;
Application.UnLock();
}
or you can follow below link
http://www.aspdotnetfaq.com/Faq/How-to-show-number-of-online-users-visitors-for-ASP-NET-website.aspx
http://www.sujitbhujbal.com/2012/12/how-to-count-website-visitors-in-aspnet.html
Sandeep Singh ShekhawatPosted Jun 19, 2013, 12:09 AM
Please go through below link
http://imar.spaanjaars.com/223/howto-create-a-hit-counter-using-the-globalasax-file-in-aspnet-1x
I hope it will be helpful.