首页 > 编程 > ASP > 正文

三、ASPNET中实现在线用户检测(使用后台守护线程)

2024-05-04 11:06:29
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

启动后台线程可以用下面的语句:
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[i] ;
        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>
<asp:label font-size="8pt" id="showmsg" runat="server"/>
<table width=450 bgcolor=white cellpadding="2" cellspacing="1" class="grid">
    <asp:label font-size="8pt" id="maininfo" runat="server"/>
</table>
</center></body></html>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表