12

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

Keith
  • 20,636
  • 11
  • 84
  • 125
Baz
  • 12,713
  • 38
  • 145
  • 268
  • 1
    Your question has been answered however an appropriate piece advice has not be offered. That is: Don't use `Request("name")`. Always explicitly use the collection required. Why MS ever included this "shortcut" I can't fathom, it just leads to confusion, abiguity and uncertainy, oh and questions like this one. – AnthonyWJones Feb 09 '12 at 10:47
  • possible duplicate of [Request() vs Request.QueryString()](http://stackoverflow.com/questions/3178536/request-vs-request-querystring) – Andreas Louv Jun 05 '15 at 07:37
  • Dup! http://stackoverflow.com/questions/3178536/request-vs-request-querystring – Jorgesys Jul 21 '15 at 18:14

3 Answers3

19

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.

Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40
2

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.

Community
  • 1
  • 1
munnster79
  • 578
  • 3
  • 16
1

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.

Craig
  • 3,253
  • 5
  • 29
  • 43