Search code examples
asp.net-mvccookiesquery-stringform-post

Why does Request["whatever"] return the cookie value?


From what I understand:

Request.Form["whatever"] will return the value from the form POST collection Request.QueryString["whatever"] will return the value from the QueryString collection (or GET) Request["whatever"] will return the value from the POST collection (if it exists) or the QueryString collection, in that order

However, I have seen that if there's a cookie called "whatever" and there is no value for "whatever" found in either POST or QueryString collections, the cookie value will be returned.

Am I mistaken or is this in fact what happens by design in ASP.Net MVC 5?


Solution

  • From the docs:

    gets the specified object from the Cookies, Form, QueryString, or ServerVariables collections

    So yes, it is very much by design that Request["whatever"] returns a cookie value.