方法
在"Global.asax"文件中添加下面事件
void Application_Start(object sender, EventArgs e)
{
Application["count"] = 0; //初始化
}
void Session_Start(object sender, EventArgs e)
{
//对Application加琐以防并行性
Application.Lock();
//添加一个在线人数
Application["Count"] = (int)Application["Count"] + 1;
//解琐
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
//对Application加琐以防并行性
Application.Lock();
//减少一个在线人数
Application["Count"] = (int)Application["Count"] - 1;
//解琐
Application.UnLock();
}
void Page_Load(Object sender , EventArgs e)
{
lblCount.Text = Application[ "Count" ].ToString();
}