using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Web;namespace System.CRM.Common{ ////// Cookie操作助手类 /// public class CookieHelper { ////// 设置一个Cookie(一天超时) /// /// Cookie的Key值 /// Cookie的Value值 public static void SetCookie(string key, string value) { SetCookie(HttpContext.Current.Response, key, value, DateTime.Now.AddDays(1)); } ////// 设置一个Cookie /// /// Cookie的Key值 /// Cookie的Value值 /// Cookie的超时时间 public static void SetCookie(string key, string value, DateTime expires) { SetCookie(HttpContext.Current.Response, key, value, expires); } ////// 移除Cookie /// /// Cookie的Key值 public static void RemoveCookie(string key) { SetCookie(HttpContext.Current.Response, key, null, DateTime.Now.AddMinutes(-1)); } ////// 获取Cookie值(查) /// /// Cookie的Key值 ///Cookie的Value值 public static string GetCookie(string key) { return GetCookie(HttpContext.Current.Request, key); } ////// 设置一个Cookie(增删改) /// /// 当前 HTTP 响应的 System.Web.HttpResponse 对象 /// Cookie的Key值 /// Cookie的Value值 /// Cookie的超时时间 private static void SetCookie(HttpResponse response, string key, string value, DateTime expires) { HttpCookie cookie = new HttpCookie(key) { Value = value, Expires = expires }; response.Cookies.Add(cookie); } ////// 获取Cookie值(查) /// /// 当前 HTTP 请求的 System.Web.HttpRequest 对象 /// Cookie的Key值 ///Cookie的Value值 private static string GetCookie(HttpRequest request, string key) { HttpCookie cookie = request.Cookies[key]; return cookie != null ? cookie.Value : null; } }}