Is there any difference between Request["xx"] vs Request.Form["xx"] ?
I’m trying to figure it out.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The former will return a value if xx exists in the QueryString, Form, Cookies, or ServerVariables collections. It will go through each one in turn till it finds a value, at which point it will return.
See the documentation on the indexer of HttpRequest.
In short, if you have a ?xx=123 on the query string, and you use Request["xx"], the string “123” will be returned, regardless of an xx key existing in the Form collection.
Method 2
Request["key"] retrieves the value from Cookies, Form, QueryString or ServerVariable.
From the documentation:
The QueryString, Form, Cookies, or ServerVariables collection member specified in the key parameter. If the specified key is not found, then Nothing is returned.
Where Request.Form["key"] retrieves it from the form (POST) collection explicitly.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0