public static void AddAllCookies(CookieContainer cookies, HttpResponseHeaders httpResponseHeaders, string url) { var all = cookies.AllCookies(); string domurl = url; int pos = domurl.IndexOf('/', 10); if (pos >= 0) { domurl = domurl.Substring(0, pos); } Uri u = new Uri(url); Uri dom = new Uri(domurl); foreach (var kvp in httpResponseHeaders) { if (kvp.Key == "Set-Cookie") { foreach (var v in kvp.Value) { var cc = GetAllCookiesFromHeader(v, u.Host); for (int i = 0; i < cc.Count; i++) { Cookie c = cc[i]; if (!all.Any(x => x.Name == c.Name)) { cookies.Add(dom, c); } } } } } }