我有两页。第一页是注册页面,用户在该页面中创建用户名和密码。第二页是登录页面,用户在其中输入用户名和密码。我想在前端验证两者匹配。我在会话中存储了用户名和密码,而不使用数据库。这不起作用,我不确定为什么:
protected void Button1_Click(object sender, EventArgs e)
{
List<Information> downloadList = (List<Information>)Session["DownloadList"];
foreach (Information obj1 in downloadList)
{
newName = String.Format("{0}", obj1.name);
newPassword = String.Format("{0}", obj1.email);
}
if(newName != TextBoxUserNameMatch.Text)
{
LabelLoginError.Text = "You Must Enter the Correct User Name";
}
else if(newPassword != TextBoxPasswordMatch.Text)
{
LabelLoginError.Text = "You Must Enter the Correct Password";
}
else
{
Response.Redirect("DownloadPage.aspx");
}
}
谁能告诉我这里哪里出错了?这是课程信息:
public class Information
{
public String name { get; set; }
public String email { get; set; }
public String phone { get; set; }
public String zip { get; set; }
public String state { get; set; }
public String login { get; set; }
public String password { get; set; }
public String reenter { get; set; }
public Information(String name, String email, String phone, String zip, String state, String login, String password, String reenter)
{
this.name = name;
this.email = email;
this.phone = phone;
this.zip = zip;
this.state = state;
this.login = login;
this.password = password;
this.reenter = reenter;
}
}
以下是我的注册页面背后的代码:
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
Information download1 = new Information("", "", "", "", "", "", "", "");
Session["Info1"] = download1;
DropDownListState.Items.Add(download1.name);
}
}
protected void ButtonRegister_Click(object sender, EventArgs e)
{
String name = TextBoxName.Text;
String email = TextBoxEmail.Text;
String phone = TextBoxPhone.Text;
String zip = TextBoxZip.Text;
String state = DropDownListState.SelectedItem.Text;
String login = TextBoxLogIn.Text;
String password = TextBoxPassword.Text;
String reenter = TextBoxReenter.Text;
if(Session["DownloadList"] == null)
{
List<Information> downloadList = new List<Information>();
Session["DownloadList"] = downloadList;
}
Information obj1 = new Information(name, email, phone, zip, state, login, password, reenter);
List<Information> downloadList2 = (List<Information>)Session["DownloadList"];
downloadList2.Add(obj1);
Session["DownloadList"] = downloadList2;
Response.Redirect("Confirmation.aspx");
我相信这些部分工作正常,因为在我的最后一页上,我打印出用户的姓名和电子邮件,而且工作正常。