Click here to Skip to main content
13,298,731 members (46,505 online)
Rate this:
Please Sign up or sign in to 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?


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 8-Nov-12 21:05pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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.
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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("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]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100