This article mainly introduces a simple example of the asp.net operation Cookie, and a friend in need can refer to the
The code is as follows: protected void Page_Load (object sender, EventArgs e) { if (! IsPostBack) { HttpCookie cookie = request.cookies["L Ogininfo "]; if (cookie!= null) { &N Bsp CB_REPWD. Checked = true; Tb_loginname.text = Uihelper.decrypt (cookie["LoginName"]); TB_PWD. Attributes.Add ("Value", Uihelper.decrypt (cookie["pwd")); else &NB Sp { TB_PWD. Attributes.Add ("Value", "Hu Jintao"); } } } protected void Btn_login_click (object sender, EventArgs e) { &NB Sp if (uihelper.getstring (session["Code"]). ToUpper ()!=this.tb_code. Text.trim (). ToUpper ()) { Ojavascript.alert ("Incorrect validation code input"); & nbsp return; } Netuserservice nerservice = contextfactory.getobject<n Etuserservice> ("Netuserservice"); String sql = string. Format ("from Netuser where Loginname= ' {0} '", Tb_loginName.Text.Trim ()); ilist<netuser> list = nerservice.find (SQL); if (list. Count > 0) { if (list[0). Status = = 2 { OJAVASCRIpt. Alert ("The account has been deactivated, please contact the Administrator"); return; { if (Nerservic E.login (Tb_loginName.Text.Trim (), Osecurity.getpwdencrypt (TB_PWD). Text.trim ())) { HttpCookie cookie = request.cookies ["Logininfo"]; if (cb_repwd. Checked) { if (cookie = = NULL) { & nbsp HttpCookie cookielogin = new HttpCookie ("Logininfo"); setcookies (cookielogin,7); Else &NBSp { I F (Uihelper.decrypt (request.cookies["Logininfo"] ["LoginName"])!= Tb_loginName.Text.Trim ()) { & nbsp Setcookies (Cookie, 7); & nbsp { } else & nbsp { setcookieexpires (cookie); &NB Sp Ojavascript.redi Rect ("/"); } else &NBSP { Ojavascript.alert ("Incorrect username or password"); } } #region Cookie ///<summary> ///setting cookies ///</s ummary> ///<param name= "Cookielogin" >httpcookie cookielogin</param> ///< param name= "Expires" > Validity </param> private void setcookies (HttpCookie cookielogin, int Expires) & nbsp { Cookielogin. values["loginName"] = Uihelper.encrypt (Tb_loginName.Text.Trim ()); Cookielogin. values["pwd"] = Uihelper.encrypt (tb_pwd. Text.trim ()); Cookielogin. Expires = DateTime.Now.AddDays (Expires); Response.appendcookie (cookielogin); } ///<summary> ///setting cookie expiration ///</summary> & nbsp ///<param name= "Cookielogin ">httpcookie cookielogin</param> private void Setcookieexpires (HttpCookie Cookielogin) { if (cookielogin!= null) { &NB Sp Cookielogin. Expires = DateTime.Now.AddDays (-1); Response.appendcookie (cookielogin); } { #endregion Setting up a cookie is actually modifying the cookie and must be reset to the customer Send cookies request.cookies cookies, response,cookies add cookies Although simple, but do not understand the error is very easy