日期:2014-05-17  浏览次数:20415 次

求助这段代码的判断哪里出错了。
db_User里三个字段username,password,ifadmin,ifadmin表示是否为管理员。T or F
下面判断如果为true,则跳转到loginAdmin.aspx
否则loginNormal.asp

调试的时候全跳转到了loginNormal.asp。求助。
--------------------分线线---------------------------------------------


    protected void Button1_Click(object sender, EventArgs e)
    {
        string str = "select username,password,ifadmin from db_User where username='" + TextBox1.Text + "'";
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        con.Open();
        cmd.CommandText = str;
        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

        if (dr.Read())
        {
            if (dr["password"].ToString() == TextBox2.Text)
            {
                if (dr["ifadmin"].ToString() == "true")
                {
                    Response.Redirect("LoginAdmin.aspx");
                }
                else
                {
                    Response.Redirect("LoginNormal.aspx");
                }
            }
            else
            {
                Response.Write(@"<script>alert('密码输入错误')</script>");
            }
        }

        else
        {
            Response.Write(@"<script>alert('对不起没有该用户名')</script>");
        }
    }

------解决方案--------------------
 Response.Redirect("LoginAdmin.aspx",true);

 Response.Redirect("LoginAdmin.aspx");
return

------解决方案--------------------
if (dr["ifadmin