Link to home
Start Free TrialLog in
Avatar of ZuZuPetals
ZuZuPetalsFlag for United States of America

asked on

C# HttpWebRequest: Cookie is downloaded but collections are empty!

The following does a simple GET from a classic ASP page:
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.somesite.asp");            
request.UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
request.CookieContainer = cookieContainer;
request.KeepAlive = true;
request.Accept = null;
request.UseDefaultCredentials = true;
request.Proxy = null;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Console.WriteLine("StatusCode=" + response.StatusCode);

Console.WriteLine("cookieContainer.Count=" + cookieContainer.Count);

Console.WriteLine("response.Cookies.Count=" + response.Cookies.Count)

Open in new window

But both collections are empty.  Any ideas why?

Here is a dump of the WebHeaderCollection:
Content-Length: 128045
Content-Type: text/html
Date: Thu, 13 Sep 2012 23:46:59 GMT
Expires: Wed, 12 Sep 2012 23:46:58 GMT
Set-Cookie: ,ASPSESSIONIDAATAAQAB=JGEEHPOAKHCNLFIJLDFIIKDL; path=/
Server: Microsoft-IIS/6.0
Cache-control: private
The cookie is clearly there!
Avatar of kaufmed
kaufmed
Flag of United States of America image

Have you tried inspecting the cookies of the response?
Avatar of ZuZuPetals

ASKER

Yes, please see line 16.
Ah, I completely glossed over that bit. I'll see if I can test it out later this evening.
ASKER CERTIFIED SOLUTION
Avatar of ZuZuPetals
ZuZuPetals
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No answer was given by community, but I offered a workaround.