如题:
我的写法是:在default.aspx.cs里
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           // if (Session["AdminLevel"] == null || Session["AdminLevel"].ToString() != "1")
            if (Session["UserName"] == null)// || Session["UserName"].ToString() != "1")
            {
                Response.Redirect("Login.aspx");
            }
        }
    }在Login.aspx.cs里:
...
SqlDataReader mydr = mycmd.ExecuteReader();
        try
        {
            if (mydr.Read())
            {
               // Session["AdminLevel"] = 1;
               // Session["UserName"]=1;
                //Session["UserName"] = "abc";
                string key = TB_username.Text;//设置用户名文本框为Cache的关键字
                string uer = Convert.ToString(Cache[key]);//读取Cache中用户相应的值
                //判断Cache中是否有用户的信息,如果没有相关的值,说明用户未登录
                if (uer == null || uer == String.Empty)
                {
                    
                    //定义cache过期时间
                    TimeSpan SessTimeout=new TimeSpan(0,0,System.Web.HttpContext.Current.Session.Timeout,0,0);
                    //TimeSpan SessTimeout = new TimeSpan(0, 0, 2, 0, 0);
                    //第一次登录时插入一个用户相关的Cache值
                    HttpContext.Current.Cache.Insert(key,key,null,DateTime.MaxValue,SessTimeout,System.Web.Caching.CacheItemPriority.NotRemovable,null);
                    //把用户名写入Session对象
                    Session["UserName"]=TB_username.Text;
                    //Session["UserName"] ="abc";                    //把权限编号写入Session对象
                    Session["RoleID"]=mydr[3];
                    Response.Write(mydr[3]);
                    Response.Redirect("default.aspx");
                }
                else
                {
                    //重复登录
                    Response.Write("");
                }
            }
            else
            {
                //显示错误信息
                LblMessage.Visible=true;
                LblMessage.Text="用户名或密码错误";
            }
        }
        finally
        {
            //关闭操作
            mydr.Close();
            myconn.Close();
        }
...
上面的问题是:当登录后,就不可以再登录了,一直出现登录画面,在调试的时候不能登录,一直出现登录页面,为什么???