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!
LVL 2
ZuZuPetalsAsked:
Who is Participating?
 
ZuZuPetalsConnect With a Mentor Author Commented:
I have no idea why the cookie isn't in one of the two collection.  However, the solution is to just parse the raw HTTP headers, grab the cookie information, and instantiate a cookie object.
0
 
käµfm³d 👽Commented:
Have you tried inspecting the cookies of the response?
0
 
ZuZuPetalsAuthor Commented:
Yes, please see line 16.
0
 
käµfm³d 👽Commented:
Ah, I completely glossed over that bit. I'll see if I can test it out later this evening.
0
 
ZuZuPetalsAuthor Commented:
No answer was given by community, but I offered a workaround.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.