频道栏目
首页 > 资讯 > C# > 正文

一个在线用户列表统计程序

10-07-11        来源:[db:作者]  
收藏   我要投稿

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace OnlineUser
{
    
public class Global : System.Web.HttpApplication
    {

        
protected void Application_Start(object sender, EventArgs e)
        {
            
#region OnlineUsers

            
try
            {
                DataTable userTable 
= new DataTable();
                userTable.Columns.Add(
"SessionID");
                userTable.Columns.Add(
"UserIP");
                userTable.Columns.Add(
"Browser");
                userTable.Columns.Add(
"OSName");
               
                userTable.AcceptChanges();
                Application.Lock();
                Application[
"OnlineUsers"= userTable;
                Application.UnLock();
            }
            
catch
            { }

            
#endregion
        }

        
protected void Session_Start(object sender, EventArgs e)
        {
            
//用Cookie是为了防止同一个用户重复计数
            HttpCookie cookie = Request.Cookies["user"];
            
if (null == cookie)//确定是否存在用户输入的cookie
            {           
                cookie 
= new HttpCookie("user");//创建一个名称是user的cookie对象
                cookie.Value = "used";//为该cookie赋值,只能是字符串,非字符串需转换
                cookie.Expires = DateTime.Now.AddHou

相关TAG标签
上一篇:Enumerable类成员函数的参数的几种写法
下一篇:C#关于类抽象类和接口之间的关系(Abstract)(Interface)
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站