public string Get(string key) { if (_httpContext == null) { throw new ArgumentNullException(nameof(_httpContext)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } if (Contains(key)) { var encodedValue = _chunkingHttpCookie.GetRequestCookie(_httpContext, key); var protectedData = string.Empty; //allow encryption is optional //may change the allow encryption to avoid this first check if cookie value is able to decode than unprotect tha data if (Base64TextEncoder.TryDecode(encodedValue, out protectedData)) { string unprotectedData; if (_dataProtector.TryUnprotect(protectedData, out unprotectedData)) { return(unprotectedData); } } return(encodedValue); } return(string.Empty); }
/// <summary> /// 根据键名获取Cookie值 /// </summary> /// <param name="key">键名</param> /// <returns>value</returns> public string Get(string key) { if (_httpContext == null) { throw new ArgumentNullException(nameof(_httpContext)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } if (Contains(key)) { var encodedValue = _chunkingHttpCookie.GetRequestCookie(_httpContext, key); var protectedData = string.Empty; if (Base64TextEncoder.TryDecode(encodedValue, out protectedData)) { string unprotectedData; if (_dataProtector.TryUnprotect(protectedData, out unprotectedData)) { return(unprotectedData); } } return(encodedValue); } return(string.Empty); }