I'm trying to share a session cookie between my HttpWebRequest
and WebBrowser
control. It was working fine until I moved the WebBrowser
into a custom control.
When I try to add the cookie, it does not get set. I have confirmed the value of the cookie I'm sending, it just doesn't add to the browser's cookie string.
Cookie is generated:
// cookieJar used for the previous HttpWebRequest
CookieCollection cc = cookieJar.GetCookies(the_url);
StringBuilder sb = new StringBuilder();
foreach (Cookie cook in cc)
{
sb.Append(cook.ToString() + ";");
}
// Confirmed cookie value below is correct: "PHPSESSID=21....";
return sb.ToString();
Cookie is sent to custom control:
// bc is my custom BrowserControl()
bc.add_cookie(c); // Fails in here
Cookie is added to WebBrowser (not working):
// Custom control method
public void add_cookie(string c)
{
// I check both values here - all looks correct
browser.Document.Cookie = c;
// I check both values again here - nothing has changed
}
Browser's cookie value (before and after - no change occurs):
// google analytics cookie (I believe)
__utma=323...; __utmb=235235...; __utmz=25235.236523.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=42346346
Keep in mind this code was working before I moved the WebBrowser to a custom control. If there's no solution I can revert the changes but I am trying to avoid that.
In short: Why isn't the cookie being added to the WebBrowser only when it's inside a custom control?