Name

ServerVariables — Var = Request.ServerVariables( key)

Synopsis

The ServerVariables collection contains several predefined environment variables in the context of the client's specific HTTP request of the web server.

The ServerVariables collection, like the other ASP collections, has the following properties:

Item

The value of a specific element in the collection. To specify an item, you can use an index number or a key.

Key

Returns the name of a specific element in the ServerVariables collection. Just as each element's value is represented by the Item property, each element's name is represented by its Key property.

If you do not know the name of a specific key, you can obtain it using its ordinal reference. For example, assume that you want to learn the key name for the third element in the collection and, subsequently, that element's value. You could use the following code:

strKeyName = Request.ServerVariables.Key(3)
strKeyValue = Request.ServerVariables.Item(strKeyName)

If, on the other hand, you know that the third element's key name is "QUERY_STRING," you could simply use the following code to retrieve the value of that element:

strKeyValue = _
          Request.ServerVariables.Item("QUERY_STRING")

Or, simply:

strKeyValue = Request.ServerVariables("QUERY_STRING")
Count

The number of elements in the collection.

As with other ASP collections, you can retrieve the value of any field of the ServerVariables collection through the use of the Item property. Note that in the following examples and ...

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.