当前位置: 代码迷 >> ASP.NET >> 关于Application Session的有关问题
  详细解决方案

关于Application Session的有关问题

热度:949   发布时间:2013-02-26 00:00:00.0
关于Application Session的问题
聊天室在Global文件里设置了
如下
private   ArrayList   al;
private   System.ComponentModel.IContainer   components   =   null;

public   Global()
{
al=new   ArrayList();
InitializeComponent();
}

protected   void   Application_Start(Object   sender,   EventArgs   e)
{
Application.Lock();
Application.Add( "al ",al);
Application[ "UserTotal "]=0;
Application[ "UserNum "]=0;
Application.UnLock();
}
 
protected   void   Session_Start(Object   sender,   EventArgs   e)
{
Application.Lock();
Application[ "UserTotal "]=int.Parse(Application[ "UserTotal "].ToString().Trim())+1;
Application[ "UserNum "]=int.Parse(Application[ "UserNum "].ToString().Trim())+1;
Application.UnLock();
}
我是用arraylist来保存登陆用户,相应的用户退出时候就应该减一,可是没有减一阿,
protected   void   Application_End(Object   sender,   EventArgs   e)
{
Application.Lock(); Application[ "UserNum "]=int.Parse(Application[ "UserNum "].ToString().Trim())-1;
Application.UnLock();
}
记录用户的界面
部分
Session[ "UserName "]=this.txtName.Text;
ArrayList   al=(ArrayList)Application[ "al "];
al.Add(Session[ "UserName "].ToString());
Response.Redirect( "Main.htm ");
请帮忙告诉我一下怎么样让他人数减一
并且移出退出用户的id???不胜感激


------解决方案--------------------------------------------------------
应该是退出后过段时间,默认10分钟吧,才会减一的吧
------解决方案--------------------------------------------------------
protected void Application_End(Object sender, EventArgs e)
{
Application.Lock(); Application[ "UserNum "]=int.Parse(Application[ "UserNum "].ToString().Trim())-1;
Application.UnLock();
}
---------------------------
应该写在Session_End里面
------解决方案--------------------------------------------------------
protected void Application_End(Object sender, EventArgs e)
{
Application.Lock(); Application[ "UserNum "]=int.Parse(Application[ "UserNum "].ToString().Trim())-1;
Application.UnLock();
}
---------------------------
应该写在Session_End里面

同意楼上,用户退出后,Application[ "UserNum "]也over了,此时减1没意义了。
  相关解决方案