asp.net C#语言if else问题 为什么if 里面跳转的页面是Main2.asp而不是Main.asp
string username = this.name.SelectedValue.Trim(); string userpassword =password.Text ; User user = new User(username, userpassword); if (username.Equals("admin")&& userpassword.Equals("123")) { Response.Redirect("Main.aspx"); }
else if (user.checkLogin()) { Response.Redirect("Main2.aspx"); } else { Response.Write("输入有误,请重新输入!"); }
checkLogin方法 public bool checkLogin() { Database db = DatabaseFactory.CreateDatabase(); string strSql = "select * from users where userName='" + name + "'and userPassword='" + password + "'"; DbCommand cmd = db.GetSqlStringCommand(strSql); IDataReader dataReader = db.ExecuteReader(cmd); if (dataReader.Read()) return true; else return false; }
------解决方案--------------------
------解决方案-------------------- if (username.Equals("admin")&& userpassword.Equals("123")) => if (username == "admin" && userpassword == "123")