/// <summary> /// 从cookie中拿到一个值 /// </summary> /// <param name="key"></param> /// <returns></returns> public static string Get(string key) { if (HttpContextHelper.GetCurrent().Request.Cookies.ContainsKey(key)) { var source = HttpContextHelper.GetCurrent().Request.Cookies[key]; if (string.IsNullOrEmpty(source)) { return(""); } var result = ""; try { result = RsaHelper.DecryptData(source, RsaHelper.privateKey); } catch { // ignored } return(result); } return(""); }
/// <summary> /// 往cookie中设置一个值 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <returns></returns> public static void Set(string key, string value) { var result = ""; if (!string.IsNullOrEmpty(value)) { try { result = RsaHelper.EncryptData(value, RsaHelper.publicKey); } catch { // ignored } } HttpContextHelper.GetCurrent().Response.Cookies.Append(key, result, new CookieOptions() { Domain = ConfigHelper.Get(ConfigHelper.CookieDomain), Path = "/" }); }