.net 中怎样实现在线人数的统计和在线会员的信息显示(就是把所有的会员的id,IP显示)!!求高人解决!!万分感谢!

解决方案 »

  1.   

    在Global.ascx中做,这样是最简单的,但是统计太粗糙.如果想要精细的统计,得用别的办法了.protected void Application_Start(Object sender, EventArgs e)
            {
                try
                {
                    long lCount = 0;
                    StreamReader sdr = new StreamReader(Server.MapPath("App_Data/count.txt"));
                    string strCount = sdr.ReadLine();
                    if (strCount != null)
                    {
                        if (strCount.Trim().Replace(((char)13).ToString(), "") != "")
                        {
                            lCount = long.Parse(strCount);
                        }
                    }
                    sdr.Close();
                    Application.Lock();
                    Application["counter"] = lCount;
                    Application.UnLock();
                }
                catch { }
            }
     
    protected void Session_Start(Object sender, EventArgs e)
    {
                try
                {
                    if (Request.ServerVariables["URL"].IndexOf("admin") == -1)
                    {
                        long lCount = 0;
                        lCount = long.Parse(Application["counter"].ToString()) + 1;
                        StreamWriter sw = new StreamWriter(Server.MapPath("App_Data/count.txt"));
                        sw.Write(lCount.ToString());
                        sw.Close();
                        Application.Lock();
                        Application["counter"] = lCount;
                        Application.UnLock();
                    }
                }
                catch { }
    }至于在线人数,在session_start里加入session判断就行了.有session的为登陆,没有的别为游客.