Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello everyone.
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. Could someone please help me?

or

Some one who logged in can see who who is currently online/active which is valid for 30 mins. from user angle.

Thanx in advance.
Posted

Use a table for storing login details. Insert a record after successful login, log out time is null. After logout update the table with logout time.
You can get the current login user details from this table.
 
Share this answer
 
u can use a table "OnlineUsers" to store data of users currently online.

Whenever a user logs in, insert his/her data in this table. In Session_End event in Global.asax file, write a code to remove row of current user.

When a session expires of timeout, it will fire "Session_End" event. When the user logs out, end session programmatically, so this event will be fired.

In this way, u can keep track of currently online users through "OnlineUsers" table.
 
Share this answer
 
Comments
Lamazhab 23-Jul-15 11:53am    
if session ends, how do you get the current user's ID in order to remove entry from OnlineUsers table? I assume user's ID is stored in a session variable which disappears when session ends.
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.

C#
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.

C#
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.

[edit] code tags added [/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900