如何在ASP.NET网站C#中查看谁在线 [英] How to see who is online in asp.net website c#

查看:70
本文介绍了如何在ASP.NET网站C#中查看谁在线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我只需要查看在线的注册用户即可.重要的是,我只需要查看使用其用户名登录并通过的登录人即可.由于我以前从未做过这样的事情,所以我不知道该如何处理.有人可以帮我吗?



某些已登录的人可以看到谁当前在线/正在活动,有效期为30分钟.从用户角度.

预先感谢.

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.

推荐答案

使用表存储登录详细信息.成功登录后插入一条记录,退出时间为空.注销后,用注销时间更新表.
您可以从此表中获取当前登录用户的详细信息.
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.


u可以使用表"OnlineUsers"存储当前在线用户的数据.

每当用户登录时,都将其数据插入此表中.在Global.asax文件的Session_End事件中,编写代码以删除当前用户的行.

当会话超时时,它将触发"Session_End"事件.用户注销后,以编程方式结束会话,因此将触发此事件.

这样,您可以通过"OnlineUsers"表跟踪当前在线用户.
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.


1.在此页面中,设置变量LastVisitTime来存储用户最后一次访问此页面的时间.

2.使用AJAX计时器,您可以在每个间隔中更新有关该用户的LastVisitTime的数据库.

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.将变量offVisitTime设置为检查该用户是否正在访问页面.

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



例如,您可以将计时器间隔"设置为2分钟,将"SpanSpace"设置为5分钟.

4.之后,您可以通过循环获取访问用户的数量以及正在访问该页面的用户.

添加了 [edit]代码标签[/edit]



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]


这篇关于如何在ASP.NET网站C#中查看谁在线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆