在global.asax.cs中实现:
//这里初始化,放在:APPLICATION中protected void Application_Start(Object sender, EventArgs e)
{
                    Application["online"]=0;//开始为0
                   Application.Lock();
}
//新的用户
protected void Session_Start(Object sender, EventArgs e)
{
                    Application.UnLock();
Application["online"]=Convert.ToString(Convert.ToInt32(Application["online"].ToString())+1);//修改
Application.Lock();
          }
//用户下线
protected void Session_End(Object sender, EventArgs e)
{
Application.UnLock();
Application["online"]=Convert.ToString(Convert.ToInt32(Application["online"].ToString())-1);//修改
Application.Lock();
}在其它页面上:
当前在线人数:<%=Application["user_sessions"]%>位!

解决方案 »

  1.   

    to  xunjie(xunjie)
    咳....痛苦  我照着你的方法做了  可是如果把   “当前在线人数:<%=Application["user_sessions"]%>位!”  
    则什么都不显示  如果放在后台 “ Label1.Text = "本站当前有:  <b>" + Application["user_sessions"].ToString() + "" + "</b>  位访问者 !";”
    则显示 Runtime Error 
    Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
    <!-- Web.Config Configuration File --><configuration>
        <system.web>
            <customErrors mode="Off"/>
        </system.web>
    </configuration>
     Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
    <!-- Web.Config Configuration File --><configuration>
        <system.web>
            <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
        </system.web>
    </configuration>
     
    这是为什么啊 ?  出现这样的问题好多此了 啊
      

  2.   

    你把它放在一个表格里,最好是首页,
    能不能显示?
    这里我写错了
    <%=Application["user_sessions"]%>位
    应是
    当前在线人数:<%=Application["online"]%>位!
      

  3.   

    to xunjie(xunjie) 
    噢  谢谢你  我们公司的服务器现在关掉了,明天在试试吧  谢谢你
      

  4.   

    不用,如果还有问题可写信到
    [email protected]