public static void Set(string cookieName, string cookieValue, System.DateTime?cookieTime, string domain, string path) { if (Cookies.Get(cookieName).Length > 0) { Cookies.Remove(cookieName); } HttpCookie httpCookie = new HttpCookie(cookieName) { Value = cookieValue }; if (domain != null) { httpCookie.Domain = domain; } if (path != null) { httpCookie.Path = path; } if (cookieTime.HasValue) { httpCookie.Expires = cookieTime.Value; } //TODO: 设置 sql 总条数为 httpOnly 属性为 true if (cookieName.IndexOf("Count") >= 0) { httpCookie.HttpOnly = true; } HttpContext.Current.Response.Cookies.Add(httpCookie); }
/// <summary> /// 获取Cookie /// </summary> /// <param name="cookieName">Cookie Name</param> /// <returns></returns> public static string Get(string cookieName) { return(Cookies.Get(cookieName, null, null)); }