标题: 三、ASPNET中实现在线用户检测(使用后台守护线程)
问天
元帅
Rank: 1


元帅勋章 终身成就勋章
UID 11493
精华 187
积分 34221
帖子 33355
威望 91
金币 13148
热心 2619
阅读权限 100
注册 2006-4-7
状态 离线
三、ASPNET中实现在线用户检测(使用后台守护线程)

启动后台线程可以用下面的语句:
CheckOnline online=new CheckOnline();

用户可以将它放到GLOBAL。ASAX中,我是没有了,只放到了一个ASPX文件中做简单的测试。如下

//start.aspx

<%@ Page Language="c#" autoEventWireup=true Debug="true" %>
<%@ Assembly Name="Soholife" %>
<%@Import Namespace="System"%>
<%@Import Namespace="Soholife"%>
<%@Import Namespace="System.Collections"%>



<script runat="Server" Language="C#">
void Page_Load(Object sender, EventArgs args)
{
    CheckOnline online=new CheckOnline();
}

</script>


<html><head>
<style type="text/css">
    td{font-size:12;}
    .bgcolor{background:#ffffcc;}
</style>
</head>
<body><center>



</center></body></html>


而我们还需要一个程序来显示当前在线拥护的数据,程序如下:

//online.aspx  

<%@ Page Language="c#" autoEventWireup=true Debug="true" %>
<%@ Assembly Name="Soholife" %>
<%@Import Namespace="System"%>
<%@Import Namespace="Soholife"%>
<%@Import Namespace="System.Collections"%>



<script runat="Server" Language="C#">
void Page_Load(Object sender, EventArgs args)
{
    OnLineUser temp= new OnLineUser();
   
    ArrayList alluser =temp.alluser;
    string str="";
    str  = "<tr bgcolor=#ffff99>";
    str  = "<td width=100 align=center class=coolbar>用户</td>";
    str  = "<td align=center width=150 class=coolbar>登陆时间</td>";
    str  = "<td align=center width=150 class=coolbar>最近时间</td>";
    str  = "<td width=100 height=20 class=coolbar>当前位置</td>";  
    str  = "</tr>";
   
   
    for ( int i = 0 ; i < alluser.Count ; i  )
    {
        Soholife.User tempuser=(Soholife.User)alluser ;
        str  = "<tr bgcolor=white>";
        str  = "<td>"   tempuser.name   "</td>";
        str  = "<td>"   tempuser.lasttime   "</td>";
        str  = "<td>"   tempuser.curtime   "</td>";
        str  = "<Td>"   tempuser.iswhere   "</td>";
        str  = "</tr>";
    }
    maininfo.Text=str;   
}

</script>
  

<html><head>
<style type="text/css">
    td{font-size:12;}
    .bgcolor{background:#ffffcc;}
</style>
<script language=javascript>
function openwindow(url,w,h)
    {
    window.open(url,"","toolbar=no,menubar=no,directories=no,status=yes,width="   w   ",height="   h   ",scrollbars=yes,resizable=yes");
    return false;
    }
</script>
</head>

<body bgcolor="#ccffcc"><center>
<Br>
<table width=450 bgcolor=white cellpadding="0" cellspacing="0" style="border:none";>
    <Tr><td colspan=2 align=center class=bar>当前在线用户</td></tr>
</table><br>
<aspabel font-size="8pt" id="showmsg" runat="server"/>
<table width=450 bgcolor=white cellpadding="2" cellspacing="1" class="Grid">
    <aspabel font-size="8pt" id="maininfo" runat="server"/>  
</table>
</center></body></html>



网友 问天 签名 - 网友社区 请您回个帖。谢谢
PR查询 免费域名 免费空间
顶部
[广告] 免费域名(Free Subdomain) 免费空间(Free hosting) PR查询(Google Pagerank)



当前时区 GMT+8, 现在时间是 2008-11-22 13:47
信产部ICP备案:京ICP备05066424号 北京市公安局网监备案:1101050648号

Powered by Discuz! 5.5.0
清除 Cookies - 联系我们 - 网友俱乐部 - Archiver - WAP