Microsoft KB Archive/219294

= How to Use the Server.Transfer Method =

Article ID: 219294

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q219294



SUMMARY
One of the new Active Server Page (ASP) features introduced with Internet Information Services (IIS) version 5.0 is a transfer method for the ASP built-in Server object.

This new method is an alternative to using the Response.Redirect method to transfer to another page, and allows the transfer of the ASP built-in and Error objects to a second page. In addition, the transfer takes place on the server instead of forcing the browser to redirect to a new page.



MORE INFORMATION
When the Server.Transfer method is called, execution of the first page is terminated and execution of the second page begins. If the first page has started writing to the response buffer, the second page appends to the buffer instead of replacing it. If buffering is on, then HTTP headers can be modified by the ASP file that it is transferred to. If buffering is off, the HTTP headers are not modifiable by the ASP file that it is transferred to, unless no content has been sent by ASP yet. Additionally, multiple transfers can be called in succession, thereby chaining pages together.

The only data transferred to a second ASP page are the ASP built- in objects and the ASP Error object values from the first request. Any variables declared by the first ASP page are not available in the second ASP page.

When you transfer to a page in another application, the Application and Session objects will contain information from the originating application. Accordingly, the ASP page that it is transferred to is treated as part of the originating application.

Example
The following example pages illustrate how the Server.Transfer method may be used. In this example, the starting page contains two forms, one using the HTTP POST method and the other using the HTTP GET method. Both pages use the same second page that detects the HTTP method and transfers to a different third page for each method used. Because the transfer method is being used, the Request Object is still populated and the correct results from the first page are displayed on the respective third page.

  Copy the following ASP code and save it as "page1.asp" (without the quotation marks): Step 1 - Form Page   Save the following code as "page2.asp" (without the quotation marks): <% @LANGUAGE="VBSCRIPT" %> Step 2 - Transfer Page <%  Select Case UCase(Request.ServerVariables("REQUEST_METHOD")) Case "POST" Server.Transfer "page3a.asp" Case "GET" Server.Transfer "page3b.asp" Case Else Response.Write "An unknown HTTP verb was used." End Select %>                         Save the following code as "page3a.asp" (without the quotation marks): <% @LANGUAGE="VBSCRIPT" %> Step 3a - POST Results Hello <% = Request.Form("Name") %>   Save the following code as "page3b.asp" (without the quotation marks): <% @LANGUAGE="VBSCRIPT" %> Step 3b - GET Results Hello <% = Request.QueryString("Name") %> 

Note: The last two pages are not complete HTML pages. This is because both pages are appending to the response buffer that was started on the second page.

To try this example, save all pages to a Web folder with "Script" access enabled and browse "page1.asp."

Additional query words: iis

Keywords: kbinfo kbscript kbcodesnippet KB219294

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.