您的位置:首页 > 编程语言 > ASP

asp.net用户登录并发数控制

2013-04-02 09:45 253 查看
登录成功后,得到允许该用户并发数的数量onlineNum;name为该用户的用户名;

Application[name + "_count"]=onlieNum;

if (Application[name + "_login"] == null)

{

string id = SiteSession.SessionId;

ArrayList arr = new ArrayList();

arr.Add(id);

Application[name + "_login"] = arr;

}

else

{

ArrayList arr = new ArrayList();

arr = (ArrayList)Application[name + "_login"];

if (arr.Count < Convert.ToInt16(Application[name + "_count"]))

{

string id = SiteSession.SessionId;

arr.Add(id);

Application[name + "_login"] = arr;

}

else

{

MessageBox.Show(Page, "超过最大连接数,请稍后再试");

return;

}

}

在global.asax文件中(防止意外退出)

void Session_End(object sender, EventArgs e)

{

// 在会话结束时运行的代码。

// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为

// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer

// 或 SQLServer,则不会引发该事件。

ArrayList arr = (ArrayList)Application[HttpContext.Current.Session["UserAccount"].ToString()+"_login"];

if(arr.Contains(HttpContext.Current.Session.SessionID))

{

arr.Remove(HttpContext.Current.Session.SessionID);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: