using System;using System.Web;using XTSoft.Com.DwCmsException;namespace XTSoft.Com.Common{ public sealed class CookieHelper { private CookieHelper() { } ////// 获取一个数组形式的Cookies /// public static HttpCookie GetCookie(string name) { if (!string.IsNullOrEmpty(name)) { return HttpContext.Current.Request.Cookies[name]; } else { throw new DwException("键值为空!"); } } ////// 移除Cookies /// public static void RemoveCookie(string name) { RemoveCookie(GetCookie(name)); } ////// 移除Cookies /// public static void RemoveCookie(HttpCookie cookie) { if (cookie != null) { cookie.Expires = new DateTime(1983, 1, 2); Save(cookie); } } ////// 保存Cookies /// public static void Save(HttpCookie cookie) { cookie.Domain = ""; HttpContext.Current.Response.AppendCookie(cookie); } ////// 获取一个新的Cookies /// public static HttpCookie GetNewCookie(string name) { return new HttpCookie(name); } ////// 取得指定名称的单值Cookie /// ///public static string GetCookieValue(string name) { HttpCookie cookie = GetCookie(name); if (cookie == null || cookie.Value == null) { return string.Empty; } else { return cookie.Value; } } /// /// 保存指定名称的单值Cookie /// ///public static void SetCookie(string name, string value) { SetCookie(name, value, DateTime.Now); } /// /// 保存指定名称的单值Cookie /// ///public static void SetCookie(string name, string value, DateTime expires) { HttpCookie cookie = GetCookie(name); if (cookie == null) { cookie = GetNewCookie(name); } cookie.Value = value; cookie.Expires = expires; Save(cookie); } /// /// 保存指定名称的单值Cookie /// ///public static void SetCookie(string name, string value, string path, DateTime expires) { HttpCookie cookie = GetCookie(name); if (cookie == null) { cookie = GetNewCookie(name); } cookie.Path = path; cookie.Value = value; cookie.Expires = expires; Save(cookie); } /// /// 保存指定名称的单值Cookie /// ///public static void SetCookie(string name, string value, string path) { SetCookie(name, value, path, DateTime.Now); } }}