欢迎光临
我们一直在努力

如何显示在线人数和所在位置-ASP教程,ASP应用

建站超值云服务器,限时71元/月

一、原理

在.net中的global.asax中有application_authenticaterequest事件和application_beginrequest事件是在每次访问aspx文件都会触发。但是application_beginrequest中不能对已经经过froms身份验证的身份ticket票进行识别。所以只能放到application_authenticaterequest中去。

我的实现原理是:每次访问aspx文件时候都会判断在线表里面是否有这个用户(已经登录了的记录用户名,没有登录的记录ip地址),如果不存在,则将该用户的身份、最后访问时间、最后访问ip、和最后访问的url存入数据库。如果数据库中已经曾在,则更新该记录,把最后访问时间,ip以及最后访问url更新。

同时,删除数据库中与当前时间间隔20分钟以上的数据(20分钟没操作当为超时)。

二、优点

这样,你不仅仅可以看到当前在线的准确人数,还知道是那些人在线,以及是否登陆,和访问人数中已经是会员的比例,以及所在位置,并计算某个页上的人数。

三、数据库结构:

主键 字段 类型 长度 是否为空说明

1uson_serialint40序号

0uson_uservarchar200用户名(没登陆则为ip)

0uson_companyvarchar1000公司名(没登陆则为游客)

0uson_ip varchar200ip地址

0uson_datedatetime80最后操作时间

0uson_urlvarchar1000最后操作页面路径

四、程序

注意:

1、程序位于global.asax中

2、我是使用的forms身份验证

3、请using system.web.security

protected void application_authenticaterequest(object sender, eventargs e)

{

string struserid = string.empty;

string strcompany = string.empty;

if (request.isauthenticated)

{

formsidentity identity = (formsidentity)user.identity;

formsauthenticationticket ticket = identity.ticket;

struserid = user.identity.name;

strcompany = ticket.userdata.split("|".tochararray())[2];

}

else

{

struserid = request.userhostaddress;

strcompany = "游客";

}

memberonlineinfo objonline = new memberonlineinfo(struserid, request.userhostaddress, datetime.now.tostring(), request.filepath, strcompany);

memberaccount account = new memberaccount();

if (!account.checkuseronline(struserid))

account.addonline(objonline);

else

account.updateonline(objonline);

//删除超时的会员

account.deleteonline();

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何显示在线人数和所在位置-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章