//加载页面,显示用户的基本信息 protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["usr"] == null) { Response.Redirect("~/Student/Login.aspx"); } //check longin HttpCookie cookie = Request.Cookies["usr"]; StudentInfo student = new StudentInfo(); student.Stu_ID = Convert.ToInt32(cookie.Values["ID"]); student.Stu_Password = cookie.Values["pass"].Trim(); if (!bllStudent.CheckLogin(student)) { Response.Redirect("~/Student/Login.aspx"); } student = bllStudent.Get(student.Stu_ID); Mailbox.Text = bllStudent.Get(Convert.ToInt32(cookie.Values["ID"])).Stu_Email; Mailbox.Attributes["ContentEditable"] = "false"; Image7.ImageUrl = student.Stu_Image; Std_Name.Text = student.Stu_UserName; Std_ID.Text = Convert.ToString(student.Stu_ID); }
//加载页面,验证用户登录信息,显示个人信息 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.Cookies["usr"] == null) { Response.Redirect("~/Student/Login.aspx"); } //check longin HttpCookie cookie = Request.Cookies["usr"]; StudentInfo student = new StudentInfo(); student.Stu_ID = Convert.ToInt32(cookie.Values["ID"]); student.Stu_Password = cookie.Values["pass"].Trim(); if (!bllStudent.CheckLogin(student)) { Response.Redirect("~/Student/Login.aspx"); } //set the value of personal information StudentInfo student2 = bllStudent.Get(student.Stu_ID); Name.Text = student2.Stu_UserName; Mailbox.Text = student2.Stu_Email; Telephone.Text = student2.Stu_Tel; Image7.ImageUrl = student2.Stu_Image; Std_Name.Text = student2.Stu_UserName; Std_ID.Text = Convert.ToString(student2.Stu_ID); if (student2.Stu_Sex != null) { Radio.Items.FindByValue(student2.Stu_Sex.Trim()).Selected = true; } } }
//验证登录 //在cookie中添加user protected void Login_Click(object sender, EventArgs e) { StudentInfo student = new StudentInfo(); StudentInfo student2 = bllStudent.GetByName(Username.Text.Trim()); if (student2 == null) { return; } student.Stu_ID = student2.Stu_ID; student.Stu_Password = Password.Text.ToString().Trim(); if (bllStudent.CheckLogin(student)) { student2.Stu_LastLogin = DateTime.Now; bllStudent.Modify(student2); HttpCookie cookie = new HttpCookie("usr"); cookie.Values["ID"] = student.Stu_ID.ToString(); cookie.Values["pass"] = Password.Text.ToString().Trim(); cookie.Expires = System.DateTime.Now.AddDays(1);//设置过期时间 1天 Response.Cookies.Add(cookie); Response.Redirect("~/Home/Home.aspx"); } }