CookieContainer doesn't save all cookies
<p>I'm using WebClient to login to Wordpress blog, my Web Client methods:</p>

<pre><code>protected override WebRequest GetWebRequest(Uri address)
    {
        WebRequest request = base.GetWebRequest(address);

        if (request.GetType() == typeof(HttpWebRequest))
        {
            ((HttpWebRequest)request).CookieContainer = cookieContainer;
            foreach (Cookie c in cookieContainer.GetCookies(address))
            {
                Console.WriteLine(" cName:   " + c.Name);
                Console.WriteLine(" cValue:  " + c.Value);
                Console.WriteLine(" cPath:   " + c.Path);
                Console.WriteLine(" cDomain: " + c.Domain);
            }
            ((HttpWebRequest)request).UserAgent = userAgent;
            ((HttpWebRequest)request).Timeout = timeout;
            ((HttpWebRequest)request).Accept = accept;
        }

        return request;
    }

    [DebuggerNonUserCode()]
    protected override WebResponse GetWebResponse(WebRequest request)
    {
        try
        {
            WebResponse response = base.GetWebResponse(request);

            if (response.GetType() == typeof(HttpWebResponse))
            {
                foreach (Cookie c in ((HttpWebResponse)response).Cookies)
                {
                    Console.WriteLine(" Name:   " + c.Name);
                    Console.WriteLine(" Value:  " + c.Value);
                    Console.WriteLine(" Path:   " + c.Path);
                    Console.WriteLine(" Domain: " + c.Domain);
                }

                characterSet = ((HttpWebResponse)response).CharacterSet;
            }

            return response;
        }
        catch (System.Net.WebException e)
        {
            throw e;
        }
    }
</code></pre>

<p>Now when I try to login wordpress send four cookies and 302 redirect</p>

<pre><code>Set-Cookie: wordpress_a235c74829f55a618a01c9f088805f08=precmast%7C1318622660%7C45c78363a5062b592b1fe49201fea5a8; path=/wp-content/plugins; httponly
Set-Cookie: wordpress_test_cookie=WP+Cookie+check; path=/
Set-Cookie: wordpress_a235c74829f55a618a01c9f088805f08=precmast%7C1318622660%7C45c78363a5062b592b1fe49201fea5a8; path=/wp-admin; httponly
Set-Cookie: wordpress_logged_in_a235c74829f55a618a01c9f088805f08=precmast%7C1318622558%7Ca28c4bf14832cbbee606cdddcad9e019; path=/; httponly
</code></pre>

<p>but WebResponse contains only 2 cookies (wth path=/) and when it automaticaly redirects it doesn't send 2 another cookies so I can't log in. Now I fixed this by handling redirects and cookies manualy from response.Headers["Set-Cookie"] and response.Headers["Location"] . But I  wonder is there any other solution?</p>

<p>Actual fix</p>

<pre><code> if (response.GetType() == typeof(HttpWebResponse))
            {
                if(response.Headers["Location"] != null)
                {

                    cookieContainer.Add(response.ResponseUri, GetAllCookiesFromHeader(response.Headers["Set-Cookie"], response.ResponseUri.Host));

                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(response.Headers["Location"]);
                    req.Method = "GET";
                    req.AllowAutoRedirect = false;
                    req.CookieContainer = cookieContainer;
                    req.UserAgent = userAgent;
                    req.Timeout = timeout;
                    req.Accept = accept;


                    return GetWebResponse(req);
                }
</code></pre>
