public static HttpCookie Parse(string value) { string[] avPairs = value.Split(';'); string[] nameValue = avPairs[0].Split('='); var cookie = new HttpCookie(nameValue[0], nameValue[1]); for (int i = 1; i < avPairs.Length; i++) { var avPair = avPairs[i]; string[] attribute = avPair.Split('='); switch (attribute[0].Trim() .ToLowerInvariant()) { case "domain": cookie.Domain = attribute[1].Trim(); break; case "path": cookie.Path = attribute[1].Trim(); break; case "expires": //todo break; case "secure": cookie.Secure = true; break; case "httponly": cookie.HttpOnly = true; break; } } return cookie; }
public static void SetCookie(this IResponse response, HttpCookie cookie) { response.Headers.Add(HttpHeaderKeys.SetCookie, cookie.ToResponseHeaderString()); }