/// <summary> /// 设置Cookie值 /// </summary> /// <param name="key">键</param> /// <param name="value">值</param> private void SetCookieValue(string key, string value) { HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(Name); if (cookie == null) { cookie = new HttpCookie(Name); HttpContext.Current.Response.AppendCookie(cookie); } if (string.IsNullOrWhiteSpace(value) && cookie.Values.AllKeys.Contains(key)) { cookie.Values.Remove(key); } else { if (Encrypt) { cookie.Values[key] = DESC.Encrypt(value); } else { cookie.Values[key] = value; } } if (Expires != 0) { cookie.Expires = CacluteExpiresTime(); } HttpContext.Current.Response.SetCookie(cookie); }
/// <summary> /// 获取Cookie值 /// </summary> /// <param name="key">键</param> /// <returns>值</returns> private string GetCookieValue(string key) { HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(Name); if (cookie == null) { return(null); } else { if (Encrypt) { return(DESC.Decrypt(cookie.Values[key])); } else { return(cookie.Values[key]); } } }