Computers & ProgrammingASPBackend Development

ASP ServerVariables Collection

The ASP ServerVariables Collection retrieves the values of predetermined environment variables and requests header information.

The ASP ServerVariables collection can provide you with quite a bit of information found in the headers such as IP addresses, server name, virtual path, request method, etc.

It is a common approach to use the ServerVariables collection to obtain your visitors’ IP address, user agent (browser) info, etc. The list of ServerVariables will depend on the server software and on the browser being used.


Request.ServerVariables (SERVER_VARIABLE)


In this example, you can use the Response.Write method in conjunction with a For..Next loop to enumerate the ServerVariables Collection

<!DOCTYPE html>
    <title>Server Variables</title>
    <style type="text/css">
        table {
            margin:20px auto;
            border:1px solid gray;
        tr {
            border:1px solid gray;
        td {
            border:1px solid gray;


For Each x In Request.ServerVariables
    Response.Write("<td>" & x & "</td><td>" & Request.ServerVariables(x) & "</td>")



The following is a listing of the server variables that can be accessed in the ASP ServerVariables Collection.

ALL_HTTPAll HTTP headers sent by the client.
ALL_RAWRetrieves all headers in raw form.
APPL_MD_PATHRetrieves the metabase path of the application.
APPL_PHYSICAL_PATHRetrieves the physical path corresponding to the meta base path.
AUTH_PASSWORDRetrieves the value entered in the client’s authentication dialog.
AUTH_TYPEThe authentication method that the server uses to validate users.
AUTH_USERRetrieves the raw authenticated user name.
CERT_COOKIERetrieves the unique ID for client certificate as a string.
CERT_FLAGSbit0 is set to 1 if the client certificate is present and bit1 is set to 1 if the certification authority of the client in invalid.
CERT_ISSUERRetrieves the issuer field of the client certificate.
CERT_KEYSIZERetrieves the number of bits in Secure Sockets Layer connection key size.
CERT_SECRETKEYSIZERetrieves the number of bits in server certificate private key.
CERT_SERIALNUMBERRetrieves the serial number field of the client certificate.
CERT_SERVER_ISSUERRetrieves the issuer field of the server certificate.
CERT_SERVER_SUBJECTRetrieves the subject field of the server certificate.
CERT_SUBJECTRetrieves the subject field of the client certificate.
CONTENT_LENGTHRetrieves the length of the content as sent by the client.
CONTENT_TYPERetrieves the data type of the content.
GATEWAY_INTERFACERetrieves the revision of the CGI specification used by the server.
HTTP_<HeaderName>Retrieves the value stored in the header HeaderName.
HTTP_ACCEPTRetrieves the value of the Accept header.
HTTP_ACCEPT_LANGUAGERetrieves a string describing the language to use for displaying content.
HTTP_COOKIERetrieves the cookie string included with the request.
HTTP_REFERERRetrieves a string containing the URL of the page that referred the request. If redirected, HTTP_REFERER is empty.
HTTP_USER_AGENTRetrieves a string describing the browser that sent the request.
HTTPSRetrieves ON or OFF depending on if the request came in through HTTPS or not.
HTTPS_KEYSIZERetrieves the number of bits in Secure Sockets Layer connection key size.
HTTPS_SECRETKEYSIZERetrieves the number of bits in server certificate private key.
HTTPS_SERVER_ISSUERRetrieves the issuer field of the server certificate.
HTTPS_SERVER_SUBJECTRetrieves the subject field of the server certificate.
INSTANCE_IDThe ID for the IIS instance in textual format.
INSTANCE_META_PATHThe meta base path for the instance of IIS that responds to the request.
LOCAL_ADDRRetrieves the server address on which the request came in.
LOGON_USERRetrieves the Windows account that the user is logged into.
PATH_INFORetrieves extra path information as given by the client.
PATH_TRANSLATEDA translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping.
QUERY_STRINGRetrieves the variables and values stored in the string following the question mark (?) in the HTTP request.
REMOTE_ADDRRetrieves the IP address of the remote host making the request.
REMOTE_HOSTRetrieves the name of the host making the request.
REMOTE_USERRetrieves an unmapped user-name string sent in by the user.
REQUEST_METHODRetrieves the method used to make the request.
SCRIPT_NAMERetrieves a virtual path to the script being executed.
SERVER_NAMERetrieves the server’s host name, DNS alias, or IP address as it would appear in self-referencing URLs.
SERVER_PORTRetrieves the port number to which the request was sent.
SERVER_PORT_SECURERetrieves a string that contains 0 or 1. If the port is secure, the value will be 1. Otherwise, 0.
SERVER_PROTOCOLRetrieves the name and revision of the request information protocol.
SERVER_SOFTWARERetrieves the name and version of the server software that answers the request and runs the gateway.
URLRetrieves the base portion of the URL.

In the case where you only need to retrieve one server_variable, you could do so by using the Request.ServerVariables collections.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top