同一账号禁止多人同时登陆

首先在Global中写如下代码:

  1. protected void Session_Start(Object sender, EventArgs e)  
  2.  ...{  
  3.  ArrayList lstName=new ArrayList();  
  4.  this.Application.Add("name",lstName);  
  5.  }  
  6.    
  7.  //****************************************************************************************************8  
  8.  protected void Session_End(Object sender, EventArgs e)  
  9.  ...{  
  10.  Application.Lock();  
  11.  string str=Session["name"].ToString();  
  12.  ArrayList lstName=(ArrayList)this.Application["name"];  
  13.  Application.UnLock();  
  14.  }  

然后在登陆页面写代码
  1. string username=this.txtName.Text.Trim();  
  2.  ArrayList lstName=(ArrayList)this.Application["name"];  
  3.  foreach(string strname in lstName)  
  4.  ...{  
  5.  if(username.Equals(strname))  
  6.  ...{  
  7.  Response.Redirect("User_Login.aspx");  
  8.  }  
  9.  }  
  10.    
  11.  lstName=(ArrayList)Application["name"];  
  12.  lstName.Add(this.txtName.Text.Trim());  
  13.  this.Application.Lock();  
  14.  this.Application["name"]=lstName;  
  15.  Session["name"]=username;  
  16.  this.Application.UnLock();  
  17.  this.Response.Redirect("main.aspx");  
原文地址:https://www.cnblogs.com/Look_Sun/p/1856695.html