[This is preliminary documentation and subject to change]

ServerVariables

The ServerVariables collection retrieves the values of predetermined environment variables.

Syntax

Request.ServerVariables (server environment variable)

 

Parameters
server environment variable
Specifies the name of the server environment variable to retrieve. It can be one of the following values.
VariableDescription
ALL_HTTPAll HTTP headers sent by the client.
ALL_RAWRetrieves all headers in 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 are sent by the client.
APPL_MD_PATHRetrieves the metabase path for the Application for the ISAPI DLL.
APPL_PHYSICAL_PATHRetrieves the physical path corresponding to the metabase path. IIS converts the APPL_MD_PATH to the physical (directory) path to return this value.
AUTH_PASSWORDThe value entered in the client's authentication dialog. This variable is available only if Basic authentication is used.
AUTH_TYPEThe authentication method that the server uses to validate users when they attempt to access a protected script.
AUTH_USERRaw authenticated user name.
CERT_COOKIEUnique ID for client certificate, returned as a string. Can be used as a signature for the whole client certificate.
CERT_FLAGSbit0 is set to 1 if the client certificate is present.

bit1 is set to 1 if the cCertification authority of the client certificate is invalid (it is not in the list of recognized CAs on the server).

CERT_ISSUERIssuer field of the client certificate (O=MS, OU=IAS, CN=user name, C=USA).
CERT_KEYSIZENumber of bits in Secure Sockets Layer connection key size. For example, 128.
CERT_SECRETKEYSIZENumber of bits in server certificate private key. For example, 1024.
CERT_SERIALNUMBERSerial number field of the client certificate.
CERT_SERVER_ISSUERIssuer field of the server certificate.
CERT_SERVER_SUBJECTSubject field of the server certificate.
CERT_SUBJECTSubject field of the client certificate.
CONTENT_LENGTHThe length of the content as given by the client.
CONTENT_TYPEThe data type of the content. Used with queries that have attached information, such as the HTTP queries GET, POST, and PUT.
GATEWAY_INTERFACEThe revision of the CGI specification used by the server. The format is CGI/revision.
HTTP_<HeaderName>The value stored in the header HeaderName. Any header other than those listed in this table must be prefixed by HTTP_ in order for the ServerVariables collection to retrieve its value.

note Note    The server interprets any underscore (_) characters in HeaderName as dashes in the actual header. For example if you specify HTTP_MY_HEADER, the server searches for a header sent as MY-HEADER.

HTTP_ACCEPTReturns the value of the Accept header.
HTTP_ACCEPT_LANGUAGEReturns a string describing the language to use for displaying content.
HTTP_USER_AGENTReturns a string describing the browser that sent the request.
HTTP_COOKIEReturns the cookie string that was included with the request.
HTTP_REFERERReturns a string that contains the URL of the page that referred the request to the current page; however, the string does not include redirect requests.
HTTPSReturns ON if the request came in through secure channel (SSL) or it returns OFF if the request is for a non-secure channel.
HTTPS_KEYSIZENumber of bits in Secure Sockets Layer connection key size. For example, 128.
HTTPS_SECRETKEYSIZENumber of bits in server certificate private key. For example, 1024.
HTTPS_SERVER_ISSUERIssuer field of the server certificate.
HTTPS_SERVER_SUBJECTSubject field of the server certificate.
INSTANCE_IDThe 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.
INSTANCE_META_PATHThe metabase path for the instance of IIS that responds to the request.
LOCAL_ADDRReturns the Server Address on which the request came in. This is important on multi-homed computers where there can be multiple IP addresses bound to the computer and you want to find out which address the request used.
LOGON_USERThe Windows account that the user is logged into.
PATH_INFOExtra path information as given by the client. You can access scripts by using their virtual path and the PATH_INFO server variable. If this information comes from a URL, it is decoded by the server before it is passed to the CGI script.
PATH_TRANSLATEDA translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping.
QUERY_STRINGQuery information stored in the string following the question mark (?) in the HTTP request.
REMOTE_ADDRThe IP address of the remote host making the request.
REMOTE_HOSTThe name of the host making the request. If the server does not have this information, it will set REMOTE_ADDR and leave this empty.
REMOTE_USERUnmapped user-name string sent in by the user. This is the name that is really sent by the user, as opposed to the names that are modified by any authentication filter installed on the server.
REQUEST_METHODThe method used to make the request. For HTTP, this is GET, HEAD, POST, and so on.
SCRIPT_NAMEA virtual path to the script being executed. This is used for self-referencing URLs.
SERVER_NAMEThe server's host name, DNS alias, or IP address as it would appear in self-referencing URLs.
SERVER_PORTThe port number to which the request was sent.
SERVER_PORT_SECUREA string that contains either 0 or 1. If the request is being handled on the secure port, then this will be 1. Otherwise, it will be 0.
SERVER_PROTOCOLThe name and revision of the request information protocol. The format is protocol/revision.
SERVER_SOFTWAREThe name and version of the server software that answers the request and runs the gateway. The format is name/version.
URLGives the base portion of the URL.

Remarks

If a client sends a header other than those specified in the preceding table, you can retrieve the value of that header by prefixing the header name with HTTP_ in the call to Request.ServerVariables. For example, if the client sends the header:

SomeNewHeader:SomeNewValue

You can retrieve SomeNewValue by using the following syntax:

<% Request.ServerVariables("HTTP_SomeNewHeader") %>
Example

This example displays several server variables by name:

<HTML>
<!-- This example displays the content of several ServerVariables. --> 
ALL_HTTP server variable = 
<%= Request.ServerVariables("ALL_HTTP") %> <BR>
CONTENT_LENGTH server variable = 
<%= Request.ServerVariables("CONTENT_LENGTH") %> <BR> 
CONTENT_TYPE server variable = 
<%= Request.ServerVariables("CONTENT_TYPE") %> <BR>
QUERY_STRING server variable = 
<%= Request.ServerVariables("QUERY_STRING") %> <BR> 
SERVER_SOFTWARE server variable = 
<%= Request.ServerVariables("SERVER_SOFTWARE") %> <BR> 
</HTML>

This example uses the VBScript For Each loop to iterate through each existing server variable name. Some will be empty if you have Anonymous Access enabled. The following script prints out all of the server variables in a table:

<TABLE BORDER="1">
<TR><TD><B>Server Variable</B></TD><TD><B>Value</B></TD></TR>
<% For Each strKey In Request.ServerVariables %> 
<TR>
<TD><%= strKey %></TD>
<TD><%= Request.ServerVariables(strKey) %></TD>
</TR>
<% Next %>
</TABLE>

This example inserts the name of the server into a hyperlink.

<A HREF= "http://<%=Request.ServerVariables("SERVER_NAME")%>/scripts/MyPage.asp">
Link to MyPage.asp
</A>
Applies To

Request Object

See Also

ClientCertificate, Cookies, Form, QueryString


© 1997-2001 Microsoft Corporation. All rights reserved.