Protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {HttpCookie cookie = Request. Cookies ["loginInfo"]; if (cookie! = Null) {cb_repwd.Checked = true; tb_loginName.Text = UIHelper. decrypt (cookie ["loginName"]); tb_pwd.Attributes.Add ("value", UIHelper. decrypt (cookie ["pwd"]);} else {tb_pwd.Attributes.Add ("value", "******") ;}} protected void btn_login_Click (object sender, eventArgs e) {if (UIHelper. getString (Session ["Code"]). toUpper ()! = This. tb_code.Text.Trim (). ToUpper () {oJavaScript. Alert ("Incorrect verification code input"); return;} NetUserService NerService = ContextFactory. GetObject
("NetUserService"); string SQL = string. Format ("from NetUser where LoginName = '{0}'", tb_loginName.Text.Trim (); IList
List = NerService. find (SQL); if (list. count> 0) {if (list [0]. status = 2) {oJavaScript. alert ("Account Disabled, please contact the Administrator"); return ;}} if (NerService. login (tb_loginName.Text.Trim (), oSecurity. getPwdEncrypt (tb_pwd.Text.Trim () {HttpCookie cookie = Request. cookies ["loginInfo"]; if (cb_repwd.Checked) {if (cookie = null) {HttpCookie cookielogin = new HttpCookie ("loginInfo"); setCookies (cookielogin, 7);} el Se {if (UIHelper. Decrypt (Request. Cookies ["loginInfo"] ["loginName"])! = Tb_loginName.Text.Trim () {setCookies (cookie, 7) ;}} else {setCookieExpires (cookie);} oJavaScript. redirect ("/");} else {oJavaScript. alert ("incorrect user name or password") ;}# region cookie ///
/// Set cookie //////
HttpCookie cookielogin///
Validity PeriodPrivate void setCookies (HttpCookie cookielogin, int Expires) {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 );}///
/// Set cookie invalidation //////
HttpCookie cookieloginPrivate void setCookieExpires (HttpCookie cookielogin) {if (cookielogin! = Null) {cookielogin. Expires = DateTime. Now. AddDays (-1); Response. AppendCookie (cookielogin) ;}# endregion
Setting cookie expiration is actually modifying the cookie. You must resend the cookie to the client.
Request. Cookies: cookie, response, and cookies are used to add Cookies.
Although simple, but not familiar with it, it is easy to make mistakes