这个是我在登陆页面里写的  
  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!Object.Equals(Request.Cookies["username"], null))
            {
                /*读取保存用户名的cookie信息,此信息保存在客户端,方便管理员减少信息输入*/
                HttpCookie userNameCookie = Request.Cookies["username"];
                this.txtUser.Text = userNameCookie.Value;
            }
        } 
    }
然后再登陆的主窗体里写的
    protected void Page_Load(object sender, EventArgs e)
    {
        /*根据session变量username是否已经建立判断管理员是否登陆了系统,其他操作页面类似*/
        if (Session["username"] == null)
        {
            Response.Redirect("~/admin/main/Login.aspx");
        }
    }现象是怎么登陆就一个劲的在登陆页面里显示了,不跳转到主页面了

解决方案 »

  1.   

    你用的是cookie存的用户信息,在主窗体中怎么是用session取数据的?我没看到你哪有用session存数据啊
      

  2.   

    本帖最后由 net_lover 于 2010-10-12 13:56:32 编辑
      

  3.   

    UP LZ还是改用Session吧 Cookies在客户端不安全
      

  4.   


    我不太会啊,那用Session我在登陆页面怎么写,在页面也要怎么弄呢?
      

  5.   

    if(Session["username"]==null)
    {}
    BasePage中判断
      

  6.   


    能多写点吗?在登陆中怎么放到Session中,在主页页面中 怎么判断是否登陆
      

  7.   

    登录时就把登录内容存在session中!
      

  8.   

    cookie 跟session 不相同吧,
      

  9.   

    BasePage是一个父类,继承自Page类,在BasePage中
    if(Session["UserInfo"]!=null){//主页面};
    else
      跳转登录以后你的页面都继承BasePage
      

  10.   


    我在登陆页面写:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["username"] = txtUser.Text();
            } 
        }
    把用户放到Session中
    在主界面写:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null)
            {
                Response.Redirect("~/admin/main/Login.aspx");
            }
        }
    做这个判断没反应啊
      

  11.   

            protected void Page_Load(object sender, EventArgs e)
      {
      if (!IsPostBack)
      {
      if (!Object.Equals(Session["username"], null))
      {
      /*读取保存用户名的cookie信息,此信息保存在客户端,方便管理员减少信息输入*/
      Session["username"]="要放入的用户名";
      this.txtUser.Text = Session["username"].ToString();
      }
      }  
      

  12.   

      protected void Page_Load(object sender, EventArgs e)
      {
      if (!IsPostBack)
      {
      if (Session["username"]!=null&&Session["username"].tostring()!="")
      {
      Session["username"]==txtUser.Text
      Response.Redirect("~/admin/main/Main.aspx");  }
    else
    {
    Response.Redirect("~/admin/main/Login.aspx");
    }
      }  
      }
      

  13.   

    一个简单的流程
    Login.aspx.cs页面一个文本框,一个按钮
    按钮Click事件
    {
    Session["UserName"]=this.txtUserName.Text;
    this.Response.Redirect("index.aspx");
    }
    index.aspx.cs代码
    Page_Load事件
    {
    if(Session["UserName"]==null)
    {
       跳转到登录不就OK了
    }
    }
      

  14.   

    Session:
    1.用户点击登录时:
    将用户ID或者用户名写进Session
    Session["UserID"]="用户ID或者用户名";
    2.判断是否登录protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if(Session["UserID"]==null)
                {
                    //用户没有登录进行的操作,如页面跳转等
                }
            }
        }
    Cookie:
    如果写进的是cookie, 则用cookie判断
    if (Request.Cookies["UserID"] != null)
    {}