首页  ·  知识 ·  云计算
NET同一账号禁止多人同时登陆
9who  http://www.cnblogs.com/9who/  综合  编辑:dezai  图片来源:网络
首先在Global中写如下代码: protected void Session_Start(Object sender, EventArgs e) ...{

首先在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();   
 }  
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");  
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");

本文作者:9who 来源:http://www.cnblogs.com/9who/
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读