string sKey = this.TextBox1.Text;
        // 得到Cache中的给定Key的值
        string sUser = Convert.ToString(Cache[sKey]);
        if(sUser==string.Empty){
        if (this.TextBox1.Text == "1") {
            TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);
            Cache.Insert(sKey, sKey, null, DateTime.MaxValue, SessTimeOut, CacheItemPriority.NotRemovable, null);
            Session["User"] = sKey;
            Response.Write("<script>alert('用户成功!')</script>");
            }
        }else{
            Response.Write("<script>alert('用户以存在!')</script>");
         }
这样写我发现。。
我把浏览器关闭后20分钟后才能在次进入

解决方案 »

  1.   

    不经常更新数据用cache,用户登录用session就可
    参考
    http://www.cnblogs.com/cancanwyq/archive/2008/08/02/1258608.html
    http://www.cnblogs.com/liushouzhao/archive/2008/04/13/1150924.html
      

  2.   

    用户登陆用session别用cache.cache用来操作大批量数据查询和显示的。
      

  3.   


     缓存是用来操作大量的查询数据的,节省时间,
      登陆用的话没必要,直接session就行
      

  4.   

    浏览器关闭时你要把session和cache清空