rt~~谢谢~

解决方案 »

  1.   

    Global.asax文件代码如下: using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.SessionState;namespace Demo
    {
        public class Global : System.Web.HttpApplication
        {
          
            protected void Application_Start(object sender, EventArgs e)
            {            Application["count"] = 0;
               
            }        protected void Application_End(object sender, EventArgs e)
            {
               
            }
            protected void Session_Start(object sender, EventArgs e)
            {
                Session.Timeout = 1;
                Application.Lock();
                Application["count"] = (int)Application["count"] + 1;
                Application.UnLock();
           
            }
            protected void Session_End(object sender, EventArgs e)
            {            Application.Lock();
                Application["count"] = (int)Application["count"] - 1;
                Application.UnLock();
            }
        }
    } 页面后台代码如下: using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;namespace Demo
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                this.Label1.Text = "当前在线人数:" + Application["count"].ToString();
            }
        }
    }  页面前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Demo._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Label" Width="128px"></asp:Label></div>
        </form>
    </body>
    </html>
      

  2.   

    在Global 中使用全局静态变量就可以了,没不要使用Application
      

  3.   

    protected void Application_Start(Object sender, EventArgs e) 
      { 
      Application["user_sessions"] = 0; 
      } 
      protected void Session_Start(Object sender, EventArgs e) 
      { 
      Application.Lock(); 
      Application["user_sessions"] = (int)Application["user_sessions"] + 1; 
      Application.Unlock(); 
      } 
      protected void Session_End(Object sender, EventArgs e) 
      { 
      Application.Lock(); 
      Application["user_sessions"] = (int)Application["user_sessions"] - 1; 
      Application.Unlock(); 
      } 
    想统计带日期的就在Session_Start事件中加上条件,写人数到一个DataTable中,对应日期和该日期人数,将DataTable保存在Application中,统计的时候取出来就行了。
      

  4.   

    严格的说http是没有状态的,所以不存在某页面的在线人数这种说法。如果你是大概是正在看这个页的,那只有在页面上加ajax心跳,服务器端做时间过期监测了。
      

  5.   

    这种方法不准确的~用户关闭了浏览器session不会立刻结束的~论坛的在线访客是如何做到的呢?
      

  6.   


    论坛的也是不准确的,如果用户直接关闭浏览器 那么数据不能及时更新。
    所以你要在关闭页面之前添加一个事件用来logout。像中国XX银行登陆后,不管是“退出”还是关闭浏览器/页面,都会弹出对话框“你已经安全退出”。然后断开connect
      

  7.   


    在Global 中使用全局静态变量就可以了,没不要使用Application
    我的意思是在Global 中使用全局静态变量中记录在线人数,不需要把数据保存在Application
      

  8.   


    fuck you! do you know the answer or not? why did you say so much pointless shit?!
      

  9.   

    要用Application_AuthenticateRequest事件和Application_BeginRequest事件结合数据库判断