Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book


Another collection provided by the Request object is ServerVariables. Any HTTP header that is sent by a client browser is available in this collection with code such as the following:

Dim strValueData as String
strValueData = Request.ServerVariable( "HeaderType" )

The standard HTTP headers are automatically defined as members of the ServerVariables collection. For example, when form data is sent to the server, the method by which it was sent can be determined from

Dim strRequestMethod as String
strRequestMethod = Request.ServerVariables( "REQUEST_METHOD" )
' Either GET or POST

You can also use the QUERY_STRING header to obtain the original unadulterated query string that was passed to the server from the browser. A great many headers are available in this collection; and some have been processed and presented in collections such a QueryString and others have not. Table 3.3 has a list of the HTTP header types that are available.

Table 3.3 The HTTP Header Types




All HTTP headers sent by the client.


Retrieves all headers in their raw form. The difference between ALL_RAW and ALL_HTTP is that ALL_HTTP places an HTTP_ prefix before the header name and the header name is always capitalized. In ALL_RAW the header name and values appear as they were sent by the client.


Retrieves the metabase path for the (WAM) Application for the ISAPI DLL.


Retrieves the physical path corresponding to the metabase path. IIS converts the APPL_MD_PATH to the physical (directory) path to return this value.


The value entered in the client's authentication dialog box. This variable is available only if Basic authentication is used.


The authentication method that the server uses to validate users when they attempt to access a protected script.


Raw authenticated username.


Unique ID for client certificate. Returned as a string. Can be used as a signature for the whole client certificate.


If the client certificate is present, bit0 is set to 1. If the Certifying Authority of the client certificate is invalid (not in the list of recognized CA on the server), bit1 is set to 1.


Issuer field of the client certificate (O=MS, OU=IAS, CN=user name, C=USA).


Number of bits in Secure Sockets Layer connection key size. For example, 128.


Number of bits in server certificate private key. For example, 1024.


Serial number field of the client certificate.


Issuer field of the server certificate.


Subject field of the server certificate.


Subject field of the client certificate.


The length of the content as given by the client.


The data type of the content. Used with queries that have attached information, such as the HTTP queries GET, POST, and PUT.


The revision of the CGI specification used by the server. The format is CGI/revision.


The value stored in the header HeaderName. Any header other than those listed in this table must be prefixed by HTTP_ for the ServerVariables collection to retrieve its value.


Returns the value of the Accept header.


Returns a string describing the language to use for displaying content.


Returns a string describing the browser that sent the request.


Returns the cookie string that was included with the request.


Returns a string containing the URL of the page that referred the request to the current page, but does not include redirect requests.


Returns ON if the request came in through a secure channel (SSL) or it returns OFF if the request is for a non-secure channel.


Number of bits in Secure Sockets Layer connection key size. For example, 128.


Number of bits in server certificate private key. For example, 1024.


Issuer field of the server certificate.


Subject field of the server certificate.


The ID for the IIS instance in textual format. If the instance ID is 1, it appears as a string. You can use this variable to retrieve the ID of the Web server instance (in the metabase) to which the request belongs.


The metabase path for the instance of IIS that responds to the request.


Returns the server address on which the request came in. This is important on multi-homed machines where multiple IP addresses can be bound to a machine and you want to find out which address the request used.


The Windows NT account that the user is logged into.


Extra path information as given by the client. You can access a script by using its virtual path and the PATH_INFO server variable. If this information comes from a URL, the server decodes it before passing it to the CGI script.


A translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping.


Query information stored in the string following the question mark (?) in the HTTP request.


The IP address of the remote host making the request.


The name of the host making the request. If the server does not have this information, it sets REMOTE_ADDR and leaves this header empty.


Unmapped username string sent in by the user. This is the name that is really sent by the user as opposed to the ones that are modified by any authentication filter installed on the server.


The method used to make the request. For HTTP, this is GET, HEAD, POST, and so on.


A virtual path to the script being executed. This is used for self-referencing URLs.


The server's host name, DNS alias, or IP address as it would appear in self-referencing URLs.


The port number to which the request was sent.


A string that contains either 0 or 1. If the request is being handled on the secure port, then this is 1. Otherwise, it is 0.


The name and revision of the request information protocol. The format is protocol/revision.


The name and version of the server software that answers the request and runs the gateway. The format is name/version.


Gives the base portion of the URL.

It's easy to use the Request.ServerVariables() method to find out some interesting information. The following code retrieves a list of helpful items and displays them in the HTML document:

REMOTE_ADDR: <%=Request.ServerVariables("REMOTE_ADDR")%><br>
REMOTE_HOST: <%=Request.ServerVariables("REMOTE_HOST")%><br>
REMOTE_USER: <%=Request.ServerVariables("REMOTE_USER")%><br>
REQUEST_METHOD: <%=Request.ServerVariables("REQUEST_METHOD")%><br>
SERVER_NAME: <%=Request.ServerVariables("SERVER_NAME")%><br>
SERVER_PORT: <%=Request.ServerVariables("SERVER_PORT")%><br>
SERVER_PROTOCOL: <%=Request.ServerVariables("SERVER_PROTOCOL")%><br>
SERVER_SOFTWARE: <%=Request.ServerVariables("SERVER_SOFTWARE")%><br>
URL: <%=Request.ServerVariables("URL")%><br>


This code is part of the page that you can find at http://www.UsingASP.net, selecting Chapter Examples, Chapter 3, then ServerVariables. You can see the rendered page in Figure 3.15.

Figure 3.15 Some server variables are shown here in the browser window.

  • + Share This
  • 🔖 Save To Your Account