1.用cach验证
TimeSpan SessTimeout = new TimeSpan(0, 0, 1,0 , 0);//重复登陆后失效的时间
//第一次登陆的时候插入一个用户相关的cache值
HttpContext.Current.Cache.Insert(key, key, null, DateTime.MaxValue, SessTimeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
DateTime.MaxValue登陆后的失效时间,最大值
SessTimeout重复登陆后失效的时间啊,上面设置的是1分钟
HttpContext.Current.Cache.Remove(这里是要消除的值);
2.身份验证票
if (User.Identity.Name != UserCode.Text.Trim())//根据输入的用户名判断
{
FormsAuthentication.SetAuthCookie(UserCode.Text.Trim(), false);//登陆成功,创建用户身份
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, UserCode.Text.Trim(), DateTime.Now, DateTime.Now.AddMinutes(30), false, "", "/"); //建立身份验证票对象
string HashTicket = FormsAuthentication.Encrypt(Ticket); //加密序列化验证票为字符串
}
FormsAuthentication.SignOut();//删除验证票