Migrating a Web Server to IIS 5.0

Previous Topic Next Topic

Environment Variables

CGI applications that inspect environment variables can continue to do so when converted to ASP. Environment variables are provided as part of the Request object ServerVariables collection.

In a CGI application, you might access the Server_Name environment variable using a line of C code like the following:

   serverName = getenv("SERVER_NAME");

or this line, written in Perl:

   serverName = $ENV{'SERVER_NAME'};

In ASP, you can use the following instruction, written in VBScript:

   serverName = Request.ServerVariables("SERVER_NAME")

You can iterate through collections such as ServerVariables in order to examine all the values they contain. The following ASP code, written in VBScript, generates an HTML table containing all the variables contained in the ServerVariables collection, with their values:

<%@ LANGUAGE=VBSCRIPT %>
<HTML>
  <BODY>
    <TABLE BORDER=1>
    <% For Each Name in Request.ServerVariables %>
    <TR>
      <TD><%= Name %></TD>
      <TD><%= Request.ServerVariables(Name)%></TD>
    </TR>
    <% Next %>
    </TABLE>
  </BODY>
</HTML>

© 1997-1999 Microsoft Corporation. All rights reserved.