[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2012-09-13
5
Medium Priority
?
905 Views
Last Modified: 2012-11-04
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!
0
Comment
Question by:ZuZuPetals
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38397277
Have you tried inspecting the cookies of the response?
0
 
LVL 2

Author Comment

by:ZuZuPetals
ID: 38398934
Yes, please see line 16.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38400168
Ah, I completely glossed over that bit. I'll see if I can test it out later this evening.
0
 
LVL 2

Accepted Solution

by:
ZuZuPetals earned 0 total points
ID: 38410740
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
 
LVL 2

Author Closing Comment

by:ZuZuPetals
ID: 38564910
No answer was given by community, but I offered a workaround.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction and Prerequisites This article describes methods for detecting whether a client browser accepts and returns HTTP cookies and whether the client browser runs JavaScript.  Most client browsers will, by default, be configured to use cooki…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question