zoukankan      html  css  js  c++  java
  • 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[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>


     

    佛为心,道为骨,儒为表,大度看世界; 技在手,能在身,思在脑,从容过生活; 三千年读史,不外功名利禄; 九万里悟道,终归诗酒田园;
  • 相关阅读:
    统计MySQL数据库硬盘占用量大小
    zookeeper 集群安装与配置
    On Java 8中文版 英雄召集令
    下划线参数转成驼峰
    在Ubuntu 18.04中安装JDK 8
    GIT和GitHub的使用总结
    Python目录
    selenium代码实例
    Fiddler请求图标含义
    Tensorflow之神经网络
  • 原文地址:https://www.cnblogs.com/taofx/p/4137288.html
Copyright © 2011-2022 走看看