You are currently offline, waiting for your internet to reconnect

How to Use the Server.Transfer Method

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
One of the new Active Server Page (ASP) features introduced withInternet Information Services (IIS) version 5.0 is a transfer methodfor the ASP built-in Server object.

This new method is an alternative to using the Response.Redirectmethod to transfer to another page, and allows the transfer of theASP built-in and Error objects to a second page. In addition, thetransfer takes place on the server instead of forcing the browserto redirect to a new page.
More information
When the Server.Transfer method is called, execution of the firstpage is terminated and execution of the second page begins. If thefirst page has started writing to the response buffer, the secondpage appends to the buffer instead of replacing it. If bufferingis on, then HTTP headers can be modified by the ASP file that itis transferred to. If buffering is off, the HTTP headers are notmodifiable by the ASP file that it is transferred to, unless nocontent has been sent by ASP yet. Additionally, multiple transferscan 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 inthe second ASP page.

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


The following example pages illustrate how the Server.Transfermethod may be used. In this example, the starting page containstwo forms, one using the HTTP POST method and the other using theHTTP GET method. Both pages use the same second page that detectsthe HTTP method and transfers to a different third page for eachmethod used. Because the transfer method is being used, theRequest Object is still populated and the correct results from thefirst page are displayed on the respective third page.
  1. Copy the following ASP code and save it as "page1.asp"(without the quotation marks):
    <html><body><h3>Step 1 - Form Page</h3><table border="1">   <tr>      <th>POST</th>      <td>         <form action="page2.asp" method="POST">         <input type="text" name="Name">         <input type="submit" value="Submit">         </form>      </td>   <tr>   </tr>      <th>GET</th>      <td>         <form action="page2.asp" method="GET">         <input type="text" name="Name">         <input type="submit" value="Submit">         </form>      </td>   </tr></table></body></html>						
  2. Save the following code as "page2.asp" (without the quotationmarks):
    <% @LANGUAGE="VBSCRIPT" %><html><body><h3>Step 2 - Transfer Page</h3><%   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%></body></html>						
  3. Save the following code as "page3a.asp" (without the quotationmarks):
    <% @LANGUAGE="VBSCRIPT" %><h3>Step 3a - POST Results</h3><p>Hello <% = Request.Form("Name") %></p></body></html>						
  4. Save the following code as "page3b.asp" (without the quotationmarks):
    <% @LANGUAGE="VBSCRIPT" %><h3>Step 3b - GET Results</h3><p>Hello <% = Request.QueryString("Name") %></p></body></html>						
Note: The last two pages are not complete HTML pages. Thisis because both pages are appending to the response buffer thatwas started on the second page.

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

Article ID: 219294 - Last Review: 06/22/2014 19:55:00 - Revision: 4.0

  • kbcodesnippet kbinfo kbscript KB219294