Last post Feb 06, 2008 07:06 AM by Punithkumar
Feb 06, 2008 05:08 AM|kem06.net|LINK
On a admin page, i just need to see the registered users who are online. And it is important that i need to see only registered one who log in the site using their user name and pass. Since i have never done such a thing before, i have no idea how to handle
this. Caould someone pls help me?
Note: That admin page and the page that greets registered users are actually the same dafault.aspx page. But the controls(webusercontrols, hyperlinks etc) are show or not based on the type of the user(admin or user).
Feb 06, 2008 07:05 AM|Punithkumar|LINK
1. In this page, set a variable LastVisitTime to store the last time the user visiting this page.
2. Use AJAX Timer, and every interval you can update database about the LastVisitTime of this user.
protected void Timer1_Tick(object sender, EventArgs e)
sql.update(update membertable set lastvisittime='" +DateTime.Now+ "' where username='" +User.Name+ "'");
3. Set the variable offVisitTime to check if this user is visiting the page.
DateTime lastvisit = Convert.ToDateTime(sql.select("select lastvisittime from membertable where username='" +User.Name+ "'"));
TimeSpan tSpanDifferent =DateTime.Now-lastvisit;
If(tSpanDifferent>SpanSpace)//SpanSpace is the variable which is the time span to chech if the user is off-visiting. And you can set it.
//The user is not visiting this page
For example, you can set Timer Interval as 2 minutes and set SpanSpace as 5 minutes.
4. After that, you can get the number of visiting users and who is visiting the page via looping.
Feb 06, 2008 07:06 AM|Punithkumar|LINK
To get number of users online..
Application("visitors_online") = 0
Session.Timeout = 20 '20 minute timeout
Application("visitors_online") = Application("visitors_online") + 1
Application("visitors_online") = Application("visitors_online") - 1
On line users: <%=Application("visitors_online")%>