我如何知道我的网站的在线用户

时间:2022-04-05 10:10:28

I am setting the value of Session["UserID"] to Id of logined user, so I can know who the user is. But I want to know all users logined my page, and show the list of them.

我将Session [“UserID”]的值设置为登录用户的Id,因此我可以知道用户是谁。但我想知道所有用户登录我的页面,并显示它们的列表。

3 个解决方案

#1


Generally, you ask "How to know who has been active in the last x minutes."

通常,您会问“如何知道最近x分钟内谁活跃了”。

Record their last activity time on each page entry, and then query that list to see who's been active in the last couple of minutes. You could extend that and record the last page they visited too, to know how many people are online, and how many people are on a specific page.

在每个页面条目上记录他们的上次活动时间,然后查询该列表以查看过去几分钟内哪些人处于活动状态。您可以扩展它并记录他们访问过的最后一页,了解有多少人在线,以及特定页面上有多少人。

You could do this by adding just a couple fields to your user-table in the database. One for the lastActivityTime, and one for lastVisitedLocation.

您可以通过向数据库中的用户表添加几个字段来完成此操作。一个用于lastActivityTime,一个用于lastVisitedLocation。

#2


the main problem you have with logged in users is that there is no guaranteed way to ensure that the number is accurate, if someone closes their browser or kills it, or loses power, the only way you have of knowing that they aren't logged in, is when their session expires, so, by default this is 20 minutes... i'm not really into the idea of persisting this information into a database, although it is valid, the same problem remains, all you can accurately show is the number of sessions asp.net thinks are active not necessarily the number of users who are still using your site Jonathans answer is the best compromise as its a point in time measure rather than a guaranteed figure.

您登录用户遇到的主要问题是,如果有人关闭浏览器或杀死浏览器或丢失电源,则无法保证数字是准确的,这是您知道他们没有登录的唯一方法在,当他们的会话到期时,所以,默认情况下这是20分钟...我不是真的想把这些信息保存到数据库中,虽然它是有效的,同样的问题仍然存在,所有你都可以准确地显示是asp.net认为活跃的会话数量不一定是仍在使用您的网站的用户数量Jonathans的答案是最佳折衷方案,因为它是一个时间点测量而不是保证数字。

#3


you can use database sessions and then use it to keep track of logged in users, once you start using database sessions tracking becomes easy,

您可以使用数据库会话,然后使用它来跟踪已登录的用户,一旦开始使用数据库会话跟踪变得容易,

no of users online will be just count of the records in the table

没有在线用户只会计算表中的记录

and since you will be having records for each logged in user in the sessions table you will be able to get the names of the users logged in too.

并且由于您将在会话表中为每个登录用户创建记录,因此您也可以获取登录用户的名称。

#1


Generally, you ask "How to know who has been active in the last x minutes."

通常,您会问“如何知道最近x分钟内谁活跃了”。

Record their last activity time on each page entry, and then query that list to see who's been active in the last couple of minutes. You could extend that and record the last page they visited too, to know how many people are online, and how many people are on a specific page.

在每个页面条目上记录他们的上次活动时间,然后查询该列表以查看过去几分钟内哪些人处于活动状态。您可以扩展它并记录他们访问过的最后一页,了解有多少人在线,以及特定页面上有多少人。

You could do this by adding just a couple fields to your user-table in the database. One for the lastActivityTime, and one for lastVisitedLocation.

您可以通过向数据库中的用户表添加几个字段来完成此操作。一个用于lastActivityTime,一个用于lastVisitedLocation。

#2


the main problem you have with logged in users is that there is no guaranteed way to ensure that the number is accurate, if someone closes their browser or kills it, or loses power, the only way you have of knowing that they aren't logged in, is when their session expires, so, by default this is 20 minutes... i'm not really into the idea of persisting this information into a database, although it is valid, the same problem remains, all you can accurately show is the number of sessions asp.net thinks are active not necessarily the number of users who are still using your site Jonathans answer is the best compromise as its a point in time measure rather than a guaranteed figure.

您登录用户遇到的主要问题是,如果有人关闭浏览器或杀死浏览器或丢失电源,则无法保证数字是准确的,这是您知道他们没有登录的唯一方法在,当他们的会话到期时,所以,默认情况下这是20分钟...我不是真的想把这些信息保存到数据库中,虽然它是有效的,同样的问题仍然存在,所有你都可以准确地显示是asp.net认为活跃的会话数量不一定是仍在使用您的网站的用户数量Jonathans的答案是最佳折衷方案,因为它是一个时间点测量而不是保证数字。

#3


you can use database sessions and then use it to keep track of logged in users, once you start using database sessions tracking becomes easy,

您可以使用数据库会话,然后使用它来跟踪已登录的用户,一旦开始使用数据库会话跟踪变得容易,

no of users online will be just count of the records in the table

没有在线用户只会计算表中的记录

and since you will be having records for each logged in user in the sessions table you will be able to get the names of the users logged in too.

并且由于您将在会话表中为每个登录用户创建记录,因此您也可以获取登录用户的名称。