检查在线/离线用户 [英] Check Online/Offline Users

查看:82
本文介绍了检查在线/离线用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网络电视和视频流媒体门户,只能由注册用户访问。现在我想查看保存在数据库中的在线/离线用户列表。用户不需要通过长时间观看电视频道或视频来移动页面。所以我认为最后的活动时间没有用。我使用了global.asax,利用了Session_Start和Session_End事件。但在这里我需要把会话TimeOut时间但不幸的是我无法使用它作为用户可以坐很长时间观看电影或电视频道...

我在所有论坛中搜索但是找不到解决方案。我是否需要ping mac或ip地址或类似的东西?请帮助我。

I am developing a Web TV and Video Streaming Portal and that can be accessed only by registered users. Now I want to check the list of online/offline users saved in database. A user don't need to move across the pages as by watching TV channel or video for long duration. So I think the last activity time would not be helpful. I used the global.asax, by utilizing the Session_Start and Session_End events. But here I need to put the session TimeOut time but Unfortunately I Can't use it as the User Can sit to watch Movie or TV channel for long time...
I searched across all the forums but failed to find the solution. Do I need to ping the mac or ip address or something like this? Please help me.

推荐答案

考虑来自OP的评论,添加如何使用会员提供商以及在线检查用户。



- 向应用程序添加和配置Asp.net成员资格提供程序。这将添加必要的存储过程和可以直接使用的表。可以参考下面。



http://mahedee.blogspot.in/2012/06/aspnet-membership-step-by-step.html [ ^ ]



- 现在我们准备使用MembershipUser.IsOnline()属性作为

http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.isonline(v = vs.110)的.aspx [ ^ ]



或Membership.GetNumberOfUsersOnline获取在线用户数



- 如果不能按预期工作,可以尝试解决方法

如下链接



http://stackoverflow.com/ questions / 10151053 / membershipuser-isonline-always-returns-false [ ^ ]



http://msdn.microsoft.com/en-us/library/system.web.security.membership.userisonlinetimewindow.aspx [ ^ ]



现在,我没有使用asp.net会员提供商,而是在网上找到了这个。但不确定,也许你也可以尝试一下。



http://code.msdn.microsoft.com/CSASPNETCurrentOnlineUserLi-0483a7f3 [ ^ ]



希望这有帮助......
Consider the Comment from the OP adding how to use membership providers as well as to check users online.

- Add and Configure the Asp.net Membership provider to the application .This will add the necessary stored procedures and the tables which can be used directly. Can refer below.

http://mahedee.blogspot.in/2012/06/aspnet-membership-step-by-step.html[^]

- Now we are ready to use the MembershipUser.IsOnline() property as
http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.isonline(v=vs.110).aspx[^]

or Membership.GetNumberOfUsersOnline to get the number of online users

- Just in case if not working as expected a workaround can be tried
as below links

http://stackoverflow.com/questions/10151053/membershipuser-isonline-always-returns-false[^]

http://msdn.microsoft.com/en-us/library/system.web.security.membership.userisonlinetimewindow.aspx[^]

Now, without using asp.net membership provider I found this in the net . But not sure about it , may be you can have a try on this too .

http://code.msdn.microsoft.com/CSASPNETCurrentOnlineUserLi-0483a7f3[^]

Hope this helps...


好吧我的朋友,



我可能无法给你任何示例代码,因为ASP.NET不是(直到现在)我的语言。但我可以为您提供一个简单的想法。它肯定会有所帮助,也基于客户端脚本,我想你需要很少的服务器端脚本,你非常擅长:)



这里是我的想法:



1.使用我称之为心跳的信息。



2.我的意思是,a简单的客户端javascript将生成一种ping消息,其中包含用户ID,并将在服务器上ping一些ASP.Net脚本,您将创建该脚本以接收ping。



3.您必须使用 setTimeOut javascript函数对javascript函数进行递归调用使用AJAX ping服务器(我只是将数据发布到你的ASP.Net脚本)。



4.脚本将使用用户ID和一些安全码(只是为了保护虚假ping)以保持将名为isOnline的数据库条目更新为布尔值true。



5.每次ping之间的超时由你决定,以便不给服务器带来了很多负担以及客户端带宽和CPU。



希望这个响应会给你一些指针来推进:)请给我的答案和你评分也可以将它标记为已解决,如果它真的解决了你的问题:)



有问候

Tushar Srivastava
Alright My friend,

I may not be able to give you any example code since ASP.NET is not (till now) my language. But I can provide you with a simple idea. It will definitely help and is also based on client-side scripting and I guess a very little server-side scripting is required that you are very good at :)

Here's my idea:

1. Use what I call a heartbeat.

2. I mean, a simple client-side javascript will generate a kind of ping message which will include user ID and will ping on the server on some ASP.Net script that you will create to receive the pings.

3. You have to use setTimeOut function of javascript to make a recursive call to a javascript function which will use AJAX to ping the server (I simply mean posting the data to your ASP.Net script).

4. The script will use the user ID and some security code (just to protect false ping) to keep update the database entry called isOnline to boolean true.

5. The timeout between each ping is decided by you so as to not put much burden on server as well as client bandwidth and CPU.

Hope that this response will give you some pointer to move ahead :) Please do rate my answer and you can also mark it as solved if it really solved your problem :)

With Regards
Tushar Srivastava


这篇关于检查在线/离线用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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