单点登陆时只要一登陆再次登陆就提示已经登陆 怎么办噢 !
先把登陆时的用户名密码放到SESSION CACHE 中。
// 生成Key
string sKey = this.txtname.Text + "_" + this.txtpassword.Text;
// 得到Cache中的给定Key的值
string sUser = Convert.ToString(Cache[sKey]);
// 检查是否存在
if (sUser == null || sUser == String.Empty)
{
// Cache中没有该Key的项目,表名用户没有登录,或者已经登录超时
// 注意下面使用的TimeSpan构造函数重载版本的方法,是进行是否登录判断的关键。
TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);
HttpContext.Current.Cache.Insert(sKey, sKey, null, DateTime.MaxValue, SessTimeOut,
System.Web.Caching.CacheItemPriority.NotRemovable, null);
Session["User"] = sKey;
// 首次登录,您可以做您想做的工作了。
Msg.Text = "<h4 style='color:red'>嗨!欢迎您访问<a href='Welcome.aspx'>Welcome.aspx";
Msg.Text += "</a>,祝您浏览愉快!:)</h4>";
}
else
{
// 在 Cache 中发现该用户的记录,表名已经登录过,禁止再次登录
Msg.Text="<h4 style='color:red'>抱歉,您好像已经登录了呀:-(</h4>";
return;
}
然后在注销的时候把所有的SESSION CACHE 都销毁 了。
Session.Abandon();
System.Web.HttpContext.Current.Session.RemoveAll();
Cache.Remove("sKey");
可再次登陆的时候还是提示已经登陆。 非得等过一段时间(我也没测要等多久)再登陆才行。
我不是在注销的时候把SESSION CACHE 都销毁了么。怎么还是不能登陆呢。
哪位高手帮看看吧。我都做两天了。郁闷