按钮单击事件我的页面不重定向到admin.aspx

时间:2017-03-22 14:49:14

标签: c# asp.net

我从admin表中重写值,然后我存储在String变量中,最后我比较值,我的代码没有重定向到另一个页面

    protected void Button1_Click(object sender, EventArgs e)
    {
        String uname = (String)txtuser.Text;
        String upass = (String)txtp.Text;
        String cuser = "";
        String cpass = "";
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HMSS"].ToString());
        conn.Open();
        String query = "select username,password from admin where username=@username";
        SqlCommand cmd = new SqlCommand(query,conn);
        cmd.Parameters.AddWithValue("username", uname);
        cmd.Parameters.AddWithValue("password", upass);
        SqlDataReader rdr = cmd.ExecuteReader();


        while (rdr.Read())
        {
            cuser = rdr["username"].ToString();
            cpass = rdr["password"].ToString();
        }


        if (cuser==uname && cpass==upass)
        {
            Session["user"] = cuser;
            Response.Redirect("admin.aspx",true);

        }

    }


}

2 个答案:

答案 0 :(得分:0)

尝试将您的情况更改为

   @font-face {
     font-family: myFont;
     src: url('LT_21152.eot');
   }

   @font-face { 
     font-family: myFont;
     src: url('LT_21152.ttf');
   }

   font-family: myFont, myFont_IE, Arial, Helvetica, sans-serif; 

   div {
     font-family: myFont;
     font-size: 2em;
   }

答案 1 :(得分:0)

您可以查看以下代码行吗?

String uname = (String)txtuser.Text;
  1. (string)不需要隐式强制转换:Text属性已经是一个字符串。

    conn.Open();

  2. 缺少conn.Close();,最好还添加try/catch

    String query =“select username,admin from admin where username = @ username”;

    cmd.Parameters.AddWithValue(“password”,upass);

  3. 为什么不在查询中同时检查密码?

    cuser = rdr [“username”]。ToString();

  4. 这意味着不允许空值

    if(cuser == uname&& cpass == upass)

  5. 区分大小写/修剪的问题。在调试中,您是否到达Response.Redirect?

    的Response.Redirect( “admin.aspx”,TRUE);

  6. 也许~/admin.aspx