技术开发 频道

网络上实现单点登陆非application


【IT168技术文档】

  看了网上的一些方法,发用application,听我老大说很危险,我看说上的一个是用cache
string str_Key = name.Text.Trim()+"_" + passwd.Text.Trim(); string str_User = Convert.ToString(Cache[str_Key]); if (str_User == String.Empty) { 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["User"] = str_Key; Response.Write("<script>alert('登陆成功!')</script>"); } else { Response.Write("<script>alert('抱歉,您好像已经登录了!)</script>"); return; }
  我发现了一个bug,就是退出网站后,就进不去了。因为cache的时间是用session的时间定的,不能改变,当我吧Session["User"]设为null以后,cache还是有效,而其我用Cache的删除方法不能将相应键的对象删除
0
相关文章