How to Use the Server.Transfer Method
ID: Q219294
|
The information in this article applies to:
-
Microsoft Internet Information Services version 5.0
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):
<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>
-
Save the following code as "page2.asp" (without the quotation
marks):
<% @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>
-
Save the following code as "page3a.asp" (without the quotation
marks):
<% @LANGUAGE="VBSCRIPT" %>
<h3>Step 3a - POST Results</h3>
<p>Hello <% = Request.Form("Name") %></p>
</body>
</html>
-
Save the following code as "page3b.asp" (without the quotation
marks):
<% @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. 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 :
Version : winnt:5.0
Platform : winnt
Issue type : kbinfo