i have an asp.net website which now i need to find the number of online users. i found couple of articles which suggest creating an application variable in global.asax file and increment it in session start event and decrement it on session end event. however with this approach im not able to get an accurate count and after 10 or 20 minutes the counter is reseted automatically. my website is in shared hosting environment and session config is stateserver any help is much appreciated...
how to find number of online users
Collapse
X
-
by implementing this method i still wont get the actual number of users ie guest users. since this is an e-com website i am forcing users to login only after the checkout process. i am looking for something that would give approximate count of both guest and logged in users..Comment
-
then you should use the Glabal.asax like
the Global.asax class may contain
Code:<script runat="server"> public static int count = 0; void Application_Start(object sender, EventArgs e) { Application["myCount"] = count; } void Session_Start(object sender, EventArgs e) { count = Convert.ToInt32(Application["myCount"]); Application["myCount"] = count + 1; } </script>
Code:protected void Page_Load(object sender, EventArgs e) { int a; a = Convert.ToInt32(Application["myCount"]); Label4.Text = a.ToString("0000"); if (a < 10) Label4.Text = "000" + Label4.Text ; else if(a<100) Label4.Text = "00" + Label4.Text; else if(a<1000) Label4.Text = "0" + Label4.Text; }
AddanComment
-
i actually did something like that before and i am decrementing the counter on session end event in global.asax file code below
Code:protected void Session_End(object sender, EventArgs e) { count = Convert.ToInt32(Application["myCount"]); Application["myCount"] = count - 1; }
Comment
-
-
You have to have something on the database updated everytime the user ask for a page.
It could be a counter for the pages shown, or anything you want
In my case, I have the sessions stored in the database, and they are updated on every request so you only have to SELECT COUNT()... FROM SESSIONS WHERE the time is now minus 10 minutes...Comment
Comment