简体   繁体   中英

Request versus Request.QueryString

What is the difference between these two in VBScript:

Request("startDate")

Request.QueryString["startDate"]

And where is Request("startDate") documented? I don't see this usage here:

http://www.w3schools.com/asp/asp_ref_request.asp

The official documentation for the Request object in ASP classic is here: http://msdn.microsoft.com/en-us/library/ms524948%28VS.90%29.aspx

Quoting the relevant part for this question:

All variables can be accessed directly by calling Request(variable) without the collection name. In this case, the Web server searches the collections in the following order:

  • QueryString
  • Form
  • Cookies
  • ClientCertificate
  • ServerVariables

If a variable with the same name exists in more than one collection, the Request object returns the first instance that the object encounters.


EDIT: AnthonyWJones made a great comment on the question: Avoid using the Request("name") syntax. In fact, this is mentioned in the documentation link above:

It is strongly recommended that when referring to members of a collection the full name be used. For example, rather than Request .("AUTH_USER") use Request.ServerVariables ("AUTH_USER"). This allows the server to locate the item more quickly.

See Request() vs Request.QueryString()

From what I understand when you use Request on it's own it will return the first matched item in the request collection. well explained in the attached solution.

Sorry to dredge up this question, but given the warnings against using Request("param"), I had to add my two cents. In this particular case there's a good reason to use Request("param") instead of Request.QueryString("param"): It allows you to write code that will accept parameters as part of a query string or when submitted through a form. I regularly run into situations where that is not only handy, but desirable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM