Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between CookieContainer and Response.Cookies collection?

I have been doing some research on this and I couldn't find a straight answer.

Are there some cookies stored in the container that I can't get to using the Response.Cookies collection? How are cookies handled between requests using these objects? Are some cookies stored in the container but not others?

like image 914
Thomas Avatar asked Sep 25 '12 22:09

Thomas


1 Answers

Judging by the tags you've used on this question, it looks like you're getting confused.

CookieContainer and CookieCollection are used with HttpWebRequest which is when your program is a HTTP client. CookieCollection stores cookies associated with a single domain name. CookieContainer stored all the cookies over all the domain names.

In ASP.NET, HttpRequest.Cookies is HttpCookieCollection and is used when your program is a HTTP server. It stores the cookies sent by the client to the server. Because there is only one domain name (i.e. yours) there is no need for a 2-dimensional collection.

The two sets of classes (CookieContainer and CookieCollection vs HttpCookieCollection) are totally unrelated with each other.

In this post I've provided some basic background on the cookie collection classes in .NET, but I don't understand your question. What is it you're trying to do?

like image 199
Dai Avatar answered Oct 08 '22 05:10

Dai