C# 尝试登录硬编码帐户时出错
我有两个文本框来输入usename和password。一个按钮登录。如果用户名和密码正确,登录将通过,但当用户名和密码错误时,我的部分有错误。我得到 错误1语法错误,应为“(” 及 错误2)预期 下面是登录按钮中的代码C# 尝试登录硬编码帐户时出错,c#,login,webforms,C#,Login,Webforms,我有两个文本框来输入usename和password。一个按钮登录。如果用户名和密码正确,登录将通过,但当用户名和密码错误时,我的部分有错误。我得到 错误1语法错误,应为“(” 及 错误2)预期 下面是登录按钮中的代码 if (txtUser.Text == "jon" && txtPass.Text == "any") { Response.Redirect("admin.aspx"); } if else (txtUser.Text == "" &&
if (txtUser.Text == "jon" && txtPass.Text == "any")
{
Response.Redirect("admin.aspx");
}
if else (txtUser.Text == "" && txtPass.Text == "")
{
lblError.Text = "Invalid user or pass";
}
如果出现其他情况,请反转
,
——这将导致语法错误
if (txtUser.Text == "jon" && txtPass.Text == "any")
{
Response.Redirect("admin.aspx");
}
else if (txtUser.Text == "" && txtPass.Text == "")
{
lblError.Text = "Invalid user or pass";
}
出于测试目的,您可能只需删除此部分:
if (txtUser.Text == "" && txtPass.Text == "")