asp.net C#语言if else问题

longwenbin0614 2012-03-15 12:48:30
为什么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;
}
...全文
136 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2012-03-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 longwenbin0614 的回复:]

为什么if 里面跳转的页面是Main2.asp而不是Main.asp?
[/Quote]
说明执行的是
else if (user.checkLogin())
{
Response.Redirect("Main2.aspx");
}
请问你输入的是什么
longwenbin0614 2012-03-15
  • 打赏
  • 举报
回复
为什么if 里面跳转的页面是Main2.asp而不是Main.asp?
longwenbin0614 2012-03-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chinajiyong 的回复:]
引用 1 楼 longwenbin0614 的回复:

为什么if 里面跳转的页面是Main2.asp而不是Main.asp?

说明执行的是
else if (user.checkLogin())
{
Response.Redirect("Main2.aspx");
}
请问你输入的是什么
[/Quote]输入的是admin 123
longwenbin0614 2012-03-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 stonespace 的回复:]
Equals重载过,应该等于==吧?

楼主设置断点跟踪一下就知道了,
[/Quote]就是不能获取username的值
longwenbin0614 2012-03-15
  • 打赏
  • 举报
回复
学过java
stonespace 2012-03-15
  • 打赏
  • 举报
回复
Equals重载过,应该等于==吧?

楼主设置断点跟踪一下就知道了,
threenewbee 2012-03-15
  • 打赏
  • 举报
回复
以前你学过Java?
threenewbee 2012-03-15
  • 打赏
  • 举报
回复
if (username.Equals("admin")&& userpassword.Equals("123"))
=>
if (username == "admin" && userpassword == "123")

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧