Count WebSite Visitors
-
Hi.. I wrote the following code to count my website visitors: (In the Global.asax) protected static int m_ActiveUsers; public static int ActiveUsers { get { return m_ActiveUsers; } } protected void Application_Start(Object sender, EventArgs e) { Application.Lock(); m_ActiveUsers=0; Application.UnLock(); } protected void Session_Start(Object sender, EventArgs e) { Application.Lock(); ++m_ActiveUsers; Application.UnLock(); } protected void Session_End(Object sender, EventArgs e) { Application.Lock(); --m_ActiveUsers; Application.UnLock(); } But the problem it doesnt give me the right number always.Some times this code tells me there is two visitors while there is no one except me.And some times it doesnt decrement the visitors count number when i exit. Do any one know how to make a better way that wont be affected by application errors and will solve my problem? "I am too late but i will never give up"
-
Hi.. I wrote the following code to count my website visitors: (In the Global.asax) protected static int m_ActiveUsers; public static int ActiveUsers { get { return m_ActiveUsers; } } protected void Application_Start(Object sender, EventArgs e) { Application.Lock(); m_ActiveUsers=0; Application.UnLock(); } protected void Session_Start(Object sender, EventArgs e) { Application.Lock(); ++m_ActiveUsers; Application.UnLock(); } protected void Session_End(Object sender, EventArgs e) { Application.Lock(); --m_ActiveUsers; Application.UnLock(); } But the problem it doesnt give me the right number always.Some times this code tells me there is two visitors while there is no one except me.And some times it doesnt decrement the visitors count number when i exit. Do any one know how to make a better way that wont be affected by application errors and will solve my problem? "I am too late but i will never give up"
-
The problem is because session_onEnd event will not be fired while you logged out of the application or closes the window. (on session end)
Thank you for your respond... If this is true(closing the window by a user wont fire Session_onEnd event)what should i do? 1-Decrease the timeout attribute of the sessionstate in web.config file?. 2-Use another event handler(other than Session_End handler )?. :confused: "I am too late but i will never give up"
-
Thank you for your respond... If this is true(closing the window by a user wont fire Session_onEnd event)what should i do? 1-Decrease the timeout attribute of the sessionstate in web.config file?. 2-Use another event handler(other than Session_End handler )?. :confused: "I am too late but i will never give up"
Please go through this article.I hope it will help you. http://codebetter.com/blogs/brendan.tompkins/archive/2005/01/25/48325.aspx
-
Please go through this article.I hope it will help you. http://codebetter.com/blogs/brendan.tompkins/archive/2005/01/25/48325.aspx
I read the article.It is very useful but there are some problems that still exist for example using File menu>close to close the Browser window or transfer to another website in the same window. "I am too late but i will never give up"