aspx代码 <% @ Page Language="C#" %><%Response.Write("当前在线人数:" + Application["whoson"]);%> 在Global.asax中的代码 <% @ Application Language = " C# " %> < script runat = " server " > void Application_Start( object sender, EventArgs e) { // 在应用程序启动时运行的代码 Application.Lock(); Application["whoson"] = 0; Application.UnLock(); } void Application_End( object sender, EventArgs e) { // 在应用程序关闭时运行的代码 } void Application_Error( object sender, EventArgs e) { // 在出现未处理的错误时运行的代码 } void Session_Start( object sender, EventArgs e) { // 在新会话启动时运行的代码 Application.Lock(); Application["whoson"] = Convert.ToInt32(Application["whoson"]) + 1; Application.UnLock(); } void Session_End( object sender, EventArgs e) { Application.Lock(); Application["whoson"] = Convert.ToInt32(Application["whoson"]) - 1; Application.UnLock(); } </ script > 转载于:https://www.cnblogs.com/sliuqin/archive/2007/01/03/610335.html