当前位置: 移动技术网 > IT编程>开发语言>c# > c#显示当前在线人数示例

c#显示当前在线人数示例

2019年07月18日  | 移动技术网IT编程  | 我要评论
1、global.asax文件: 复制代码 代码如下:<%@ application language="c#" %><%@ import namesp

1、global.asax文件:

复制代码 代码如下:

<%@ application language="c#" %>
<%@ import namespace="system.xml" %>
<script runat="server">

    void application_start(object sender, eventargs e)
    {
        // 在应用程序启动时运行的代码
        //载入配置文档
        xmldocument appconfig = new xmldocument();
        appconfig.load(httpcontext.current.server.mappath("~/appconfig.xml"));


        //读取配置信息
        xmlnode xnlist = appconfig.getelementsbytagname("dblist")[0];
        xmlelement xedb1 = (xmlelement)xnlist.childnodes[0];
        xmlelement xedb2 = (xmlelement)xnlist.childnodes[1];
        application["db1user"] = xedb1.getattribute("user");
        application["db1source"] = xedb1.getattribute("source");
        application["db2user"] = xedb2.getattribute("user");
        application["db2source"] = xedb2.getattribute("source");
        application["count"] = 0;
    }   
    void application_end(object sender, eventargs e)
    {
        //在应用程序关闭时运行的代码
    }
    void application_error(object sender, eventargs e)
    {
        //在出现未处理的错误时运行的代码
    }
    void session_start(object sender, eventargs e)
    {
        //在新会话启动时运行的代码
        application["count"] = convert.toint32(application["count"])+1;       
    }
    void session_end(object sender, eventargs e)
    {
        //在会话结束时运行的代码。
        // 注意: 只有在 web.config 文件中的 sessionstate 模式设置为
        // inproc 时,才会引发 session_end 事件。如果会话模式
        //设置为 stateserver 或 sqlserver,则不会引发该事件。
        application["count"] = convert.toint32(application["count"]) - 1;
    }   
</script

2、显示页面:

前台:

复制代码 代码如下:

<span  id="span1" runat="server" class="bottom"> </span>

后台:

复制代码 代码如下:

span1.innerhtml = "当前在线" + application["count"].tostring() + "人";

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网