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

ASP.NET 2.0防止同一用户同时登陆

2008-06-17 15:28 786 查看
放在登陆成功的地方:  

string key = TextBox1.Text; //用户名文本框设为cache关键字   

string uer = Convert.ToString(Cache[key]); //读取cache中用户相应的值   

//判断cache中是否有用户的信息,如果没有相关的值,说明用户未登陆   

if (uer == null || uer == String.Empty)   

{   

//定义cache过期时间

TimeSpan SessTimeout = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);   //第一次登陆的时候插入一个用户相关的cache值,   

HttpContext.Current.Cache.Insert(key, key, null, DateTime.MaxValue, SessTimeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);   

Session["ADMINID"] = TextBox1.Text;   Response.Redirect("main.aspx");   

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