点跳转时..在config里的用户名能成功..但登录数据库里的user_rule=1的用户名跳转没反应..   protected void Btn_enter_Click(object sender, EventArgs e)
    {
        String strconn = System.Configuration.ConfigurationManager.AppSettings["asd"];
        SqlConnection cn = new SqlConnection(strconn);
        cn.Open();
        string strsql="select * from user_login where user_name='"+Tbx_username+"'and user_password='"+Tbx_userpwd+"'";
        SqlCommand cm = new SqlCommand(strsql, cn);
        SqlDataReader dr = cm.ExecuteReader();
      
            if (System.Web.Security.FormsAuthentication.Authenticate(this.Tbx_username.Text, this.Tbx_userpwd.Text))
            {                                                    //用户名和密码若在 配置文件web.config中,则进入管理员模块。
                System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.Tbx_username.Text, false);
                Response.Redirect("manager/man_login.aspx");
            }            else if (dr.Read())
            {
                Session["Suser_name"] = dr["user_name"];
                Session["Suser_password"] = dr["user_password"];
                Session["Suser_rule"] = dr["user_rule"];
                if ((int)Session["Suser_rule"] == 1)
                {
                    Response.Redirect("Default.aspx");
                }            }        
        
        dr.Close();
        cn.Close();
    }
         

解决方案 »

  1.   

    Session["Suser_rule"] = dr["user_rule"]; 断点调试一下,看看你的User_Rule的值
      

  2.   

    if ((int)Session["Suser_rule"] == 1) 
                    { 
                        Response.Redirect("Default.aspx"); 
                    } 
    这个判断通过了么??
    通过了应该能跳转啊..
    还是你Default.aspx页面的路径不对哈?
      

  3.   

    路径没错...应该 这段代码哪里有问题
     else if (dr.Read()) 
                { 
                    Session["Suser_name"] = dr["user_name"]; 
                    Session["Suser_password"] = dr["user_password"]; 
                    Session["Suser_rule"] = dr["user_rule"]; 
                    if ((int)Session["Suser_rule"] == 1) 
                    { 
                        Response.Redirect("Default.aspx"); 
                    }             } 
      

  4.   

    if ((int)Session["Suser_rule"] == 1) 
    断点调试,看看这句
    另外去看下 sql注入
    你的代码很危险
      

  5.   

    if (int.Parse(Session["Suser_rule"].ToString()) == 1) 
                    { 
                        Response.Redirect("Default.aspx"); 
                    } 
      

  6.   

    1断点查看Session["Suser_rule"] 的指,
    2然后看路径是否正确
      

  7.   

     你这样子的传值方式不安全,很容易被sql注入
      

  8.   

    用session保存角色,就不要FormsAuthentication.Authenticate了
    if (FormsAuthentication.Authenticate(txtUserName.Text,txtPassword.Text))
                FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
            else Response.Write("");