同一账号禁止多人同时登陆
首先在Global中写如下代码:
- protected void Session_Start(Object sender, EventArgs e)
- ...{
- ArrayList lstName=new ArrayList();
- this.Application.Add("name",lstName);
- }
- //****************************************************************************************************8
- protected void Session_End(Object sender, EventArgs e)
- ...{
- Application.Lock();
- string str=Session["name"].ToString();
- ArrayList lstName=(ArrayList)this.Application["name"];
- Application.UnLock();
- }
然后在登陆页面写代码
- string username=this.txtName.Text.Trim();
- ArrayList lstName=(ArrayList)this.Application["name"];
- foreach(string strname in lstName)
- ...{
- if(username.Equals(strname))
- ...{
- Response.Redirect("User_Login.aspx");
- }
- }
- lstName=(ArrayList)Application["name"];
- lstName.Add(this.txtName.Text.Trim());
- this.Application.Lock();
- this.Application["name"]=lstName;
- Session["name"]=username;
- this.Application.UnLock();
- this.Response.Redirect("main.aspx");
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步