为什么结束会话时,userCount没有减小?

来源:百度知道 编辑:UC知道 时间:2024/05/28 20:07:41
我启动四个窗口,分别显示UserCount1,UserCount2,UserCount3,UserCount4;
我再把第四个窗口关掉,将第一个窗口刷新.它显示UserCount4而不是UserCount3.
Global.asax代码:
<%@ Application Language="C#" %>

<script runat="server">

void Application_Start(Object sender, EventArgs e) {

Application.Add("userCount", 0);
}
void Application_End(Object sender, EventArgs e) {
}
void Session_Start(Object sender, EventArgs e) {
int userCount = int.Parse(Application.Get("userCount").ToString());
userCount++;
Application.Set("userCount", userCount);
}
void Session_End(Object sender, EventArgs e) {
int userCount = int.Parse(Application.Get("userCount").ToString());
userCount--;
Application.Set("userCount", userCount);

}

直接关闭网页不会触发Session_End事件
除非Session过期或者是调用Session.Abandon方法时才会触发该事件
另外
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
这是 Session_End事件自带的说明

不是很清楚你说的是什么啊