可以在.CS代码里用C#语言取得吗?

解决方案 »

  1.   


    在   Global.apx.cs   文件
    protected   void   Session_Start(Object   sender,   EventArgs   e)  
      {  
              Application.Lock();  
              Application["SessionCount"]   =   (int)Application["SessionCount"]   +   1;  
              Application.UnLock();  
      }  
       
      protected   void   Session_End(Object   sender,   EventArgs   e)  
      {  
              Application.Lock();  
              Application["SessionCount"]   =   (int)Application["SessionCount"]   -   1;  
              Application.UnLock();  
      }   
      

  2.   

    计算服务器端所有session的数量
      

  3.   

    "计算服务器端所有session的数量"能把语句写出来吗?
      

  4.   

    能不能说的详细点,我没用过Global.aspx这个文件。这2个函数又是怎么触发的呢?非常感谢~
      

  5.   

    这两个事件不用你触发,当一个Session开始和结束自然就触发了
      

  6.   

    Global.aspx<%@ Application Language="C#" %><script runat="server">
        void Application_Start(object sender, EventArgs e) 
        {
            // 在应用程序启动时运行的代码
            //SocutKey.Go();
            Application["userCount"] = 0;
        }
        
        void Application_End(object sender, EventArgs e) 
        {
            //  在应用程序关闭时运行的代码    }
            
        void Application_Error(object sender, EventArgs e) 
        { 
            // 在出现未处理的错误时运行的代码    }    void Session_Start(object sender, EventArgs e) 
        {
            // 在新会话启动时运行的代码
            Application.Lock();
            Application["userCount"] = (int)Application["userCount"] + 1;
            Application.UnLock();    }    void Session_End(object sender, EventArgs e) 
        {
            // 在会话结束时运行的代码。 
            // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
            // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer 
            // 或 SQLServer,则不会引发该事件。    }
           
    </script>在需要统计的页面.cs文件中
            Label1.Text = Application["userCount"].ToString();再在需要统计的页面.aspx文件中
    共有<asp:Label ID="Label1" runat="server"></asp:Label>人在线