All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,2.0的Web,Part,Framework_.net资料_编程技术
mssql存储过程类型详解_mssql学习_编程技术
定义标题的最好方法_[Html教程]
c#编程中学习数据结构的必要性
三步堵死SQL注入漏洞_[SQL,Server教程]
PHP技巧:PHP中密码加密函数_[PHP教程]
轻松掌握Ajax.net系列教程五:使用TextBoxWatermarkExtender_[Asp.Net教程]
ASP.NET,2.0中创建内容页_[Asp.Net教程]
在PHP的图形函数中显示汉字_php资料_编程技术
最近写的一个PHP操作Access类(PHP+ODBC+Access)_php资料_编程技术
Reading number is top 10 pictures
Terrorist smile the largest human history an explosion2
沙漠里的美女
迷人的靓女
Sell the barbecue as says father du breul2
Sanya, hainan Haitian party feast promiscuity
5 meters long centenarians python and melee was successfully capture king snake (figure)
Forced sex girl living abroad2
Athena chu perspective cheongsam shine with New York
Look at the Spring Festival people crowded into the what kind
Female model behind the bitterness, often being overcharged4
Download software ranking
Tram sex maniac 2 (H) rar bag14
Unix video tutorial11
徐若瑄成名作“魔鬼天使”
虚拟机汉化软件
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
Tram sex maniac 2 (H) rar bag9
Ashlynn Video2
塘西风月痕
传奇私服架设教程
Boxer vs Yellow1
aaa published in(发表于) 2013/12/17 7:45:35 Edit(编辑)
ASP.NET,2.0实现防止同一用户同时登陆_.net资料_编程技术

ASP.NET,2.0实现防止同一用户同时登陆_.net资料_编程技术

ASP.NET 2.0实现防止同一用户同时登陆_.net资料_编程技术-你的首页-uuhomepage.com

  要防止同一用户同时登陆,首页应该记录在线用户的信息(这里与用户名为例),然后判断正在登陆的用户里面是否已存在。在这里使用一个cache存放已经登陆的用户名,但是还有一个问题就是要知道用户是什么时候离开系统的呢?这就要定期清除cache中的内容了,也就是设置一个cache的时间。这个时间可以跟用户的session值联系起来,刚好当用户session值失效的时候该用户在cache里面的信息也会被清空.这样就达到了防止同时登陆的效果,具体代码如下:


  放在登陆成功的地方:


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");
}
else
{
 //重复登陆
 Response.Write("");
}





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.