I've seen this in some code and I'm a little confused about when you would use that method. Sure, the Get()
method makes sense for a request, but wouldn't you ordinarily use a Set()
method for cookies in the Response.Cookies
object, rather than Request.Cookies
?
Asked
Active
Viewed 2,403 times
1

larryq
- 15,713
- 38
- 121
- 190
-
1Did you have a look at that thread : http://stackoverflow.com/questions/573922/when-to-use-request-cookies-over-response-cookies – GeorgesD Dec 17 '12 at 16:05
-
Yes I did. It does a fine job explaining that typically you set response cookies and get request cookies. But when (under what circumstances) would you set a request cookie? – larryq Dec 17 '12 at 16:17
1 Answers
2
Let's say you have some code that expects a cookie in the request, but under some circumstances this cookie is not present. In this case you could set the cookie in the request to a default value.
Also, if you are testing code that relies on cookies being present in the request (when doing unit testing for example), then of course you need a way to set cookies without a browser (unit testing calls for testing code in isolation).

Michiel van Oosterhout
- 22,839
- 15
- 90
- 132