//------------单点登录
// 作为唯一标识的str_Key,应该是唯一的,这可根据需要自己设定规则。
// 做为测试,这里用用户名和密码的组合来做标识;也不进行其它的错误检查。
// 生成str_Key
str_Key = TextBox1.Text + "_" + TextBox2.Text;
// 得到Cache中的给定str_Key的值
string str_User = Convert.ToString(Cache[str_Key]);
// Cache中没有该str_Key的项目,表名用户没有登录,或者已经登录超时
if (str_User == String.Empty)
{
// TimeSpan构造函数,用来重载版本的方法,进行判断是否登录。
TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
HttpContext.Current.Cache.Insert(str_Key, str_Key, null, DateTime.MaxValue, SessTimeOut, CacheItemPriority.NotRemovable, null);
Session["AAA"] = str_Key;
// 首次登录成功
Response.Redirect(@"Master.aspx");
}
else
{
Response.Write("<script language=javascript>alert('用户已经在线')</script>");
return;
}
//------------单点登录