Request["key"] vs Request.Params["key"] vs Request.QueryString["key"]
Which method do you seasoned programmers use? and why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I recommend
Request.QueryString["key"]. There isn’t a lot of difference toRequest["Key"]for a query string but there is a big(er) difference if you are trying to get the value fromServerVariables.Request["Key"]looks for a value inQueryStringif null, it looks atForm, thenCookieand finallyServerVariables.Using
Paramsis the most costly. The first request to params creates a newNameValueCollectionand adds each of theQueryString,Form,CookieandServerVariablesto this collection. For the second request on it is more performant thanRequest["Key"].Having said that the performance difference for a couple of keys is fairly negligable. The key here is code should show intent and using
Request.QueryStringmakes it clear what your intent is.