public static LoginCookieInfo ReadCookie() { HttpCookie c = HttpContext.Current.Request.Cookies[name]; if (c == null) { return new LoginCookieInfo() { PassWord="", UserName=""}; } LoginCookieInfo t = new LoginCookieInfo(); t.UserName = Microsoft.JScript.GlobalObject.decodeURIComponent(c.Values["UserName"]); t.PassWord = EncryptUtil.Decrypt(c.Values["Password"]); return t; }
public static void WriteCookie(LoginCookieInfo info, DateTime? expires) { HttpCookie cookie = new HttpCookie(name); cookie.Values.Add("UserName", Microsoft.JScript.GlobalObject.encodeURIComponent(info.UserName)); cookie.Values.Add("Password", EncryptUtil.Encrypt(info.PassWord)); if (expires.HasValue) cookie.Expires = expires.Value; if (HttpContext.Current.Request.IsSecureConnection) { cookie.Secure = true; cookie.HttpOnly = true; } HttpContext.Current.Response.Cookies.Add(cookie); }