I use both of these many times in my code and don’t really know what the difference is , if a cookie is set shouldn’t it be exactly the same in request and response? and is request going to the the most up to date , or response?
EDIT:
ok , I get the difference between a request and a response, but if I type
string a = HttpContext.Current.Request.Cookie["a"].Value;
it is most of the time the same as
string a = HttpContext.Current.Response.Cookie["a"].Value;
but I am wondering what is the difference between using the two.
As everyone says
Request.Cookiesare supposed to be cookies coming from client (browser) andResponse.Cookiesare cookies that will be send back to client (browser).There is
black magicwell documented* code that copies values fromResponsecookies toRequest.Cookieswhen you add cookies toResponse. As result it looks like you have same cookies in bothRequestandResponse. Note that these copied cookies did not come from the client… so beware of making wrong decisions.Here is a link to discussion about the code: http://forums.asp.net/t/1279490.aspx. In particular, cookies added in the following way will show up in the
Request.Cookiescollection:*The behavior of cookies getting copied from
Response.Cookiesis documented in theHttpResponse.Cookiesarticle: