Using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using System.Data; 8 9 public partial class _default:system.web.ui.page {protected void Page_Load (object sender, EventArgs e) 12 {if (! IsPostBack) 14 {15//Read saved COOKIE information HttpCookie cookies = request.cookies["User_cookie"];17 if (cookie = null) 18 {19//If the cookie is not empty, the user name and password inside the cookie are read out and assigned to the foreground text box. This.txtUserName.Text = cookies["UserName"];21 this.txtPassword.Attributes.Add ("value", cookies["UserPassword"]); 22//The option to remember the password is still selected here. this.ckbRememberLogin.Checked = true;24}25}26}27-protected void ASPXB Utton1_click (object sender, EventArgs e) {string UserName = txtusername.text;31 string Password = Txtpassword.text;32 This usertable is the user information that the data layer obtains. The DataTable usertable = new Usermanager (). Getusertable (UserName);//usertable.rows.count>0 Note that there is a corresponding record in the database and you can continue execution. if (UserTable.Rows.Count > 0) 36 {37//If the password obtained from the cookie is consistent with the password in the database, the login is successful. F (usertable.rows[0]["Password"). ToString () = = Password) (HttpCookie cookie = new HttpCookie ("User_cookie") if (this.ckbRememberLogin.Checked) 42 {43//All verification information is detected, if the user chooses to remember the password , the user name and password are written to the cookie and stored. Cookies. Values.add ("UserName", This.txtUserName.Text.Trim ()); Values.add ("UserPassword", This.txtPassword.Text.Trim ()); 46//This is the setting of the cookie expiration time, here set one weeks time, after one weeks after the state security Automatically emptied. Cookies. Expires = System.DateTime.Now.AddDays (7.0); HttpContext.Current.Response.Cookies.Add (cookie); 49 }50 else51 {cookie["User_cookie"]! = null) 53 {54 If the user does not choose to remember the password, the information in the cookie is immediately set and the setting status remains immediately expired. response.cookies["User_cookie"]. Expires = datetime.now;56}57}58//scriptmanager.registerclientscript Block (this, this.) GetType (), "Script", "<script>alert ('" + ex. Message + "') </script>", false); Response.Redirect ("Default.aspx"); 61 62}63 }64}65}
(GO) ASP. NET inside easy to remember user name and password