Using the Server.Execute Method
ID: Q224363
|
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 an execute method
for the ASP built-in server object. This new method allows an ASP
page to execute a child ASP page and treat it as part of the
parent page.
MORE INFORMATION
Unlike the Server Side Includes (SSI) #exec command in IIS, which
is used to run an executable file, or the SSI #include command,
which is also used in ASP, the Server.Execute method is used with
ASP pages to execute another ASP page. This allows greater
flexibility in ASP execution by allowing conditional
execution.
For example, the #include command is processed before the page is
executed, whereas the Server.Execute method can be used after the
page processing is started, allowing the programmer to choose
which page to execute depending on user input.
The following example ASP code illustrates the Server.Execute
method and conditional execution.
Save the following ASP code as "Execute.asp" (without the
quotation marks) to a Web folder with Script Access
enabled:
<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Server.Execute Example</title>
</head>
<body>
<h2 align="center">Server.Execute Example</h2>
<h3 align="center">Default Page</h3>
<p align="center">This page is executing at<br>
<%=Request.ServerVariables("URL")%></p>
<div align="center"><center>
<form action="<%=Request.ServerVariables("URL")%>" method="GET">
<select name="page">
<option value="">Default Page</option>
<option value="page1.asp">Page One</option>
<option value="page2.asp">Page Two</option>
</select>
<input type="submit" value="Request Page">
</form>
<% If Request.QueryString("page")="" Then %>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<td>
<p><a href="page1.asp">Browse Page One</a><br>
<% Server.Execute "page1.asp" %></p>
</td>
<td>
<p><a href="page2.asp">Browse Page Two</a><br>
<% Server.Execute "page2.asp" %></p>
</td>
</tr>
</table>
<% Else %>
<p><a href="<%=Request.QueryString("page")%>">
Browse <%=Request.QueryString("page")%></a><br>
<% Server.Execute Request.QueryString("page") %></p>
<% End If%>
</center></div>
</body>
</html>
Save the following page in the same Web folder as
"Page1.asp":
<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Page 1</title>
</head>
<body>
<h3 align="center">Page 1</h3>
<p align="center">This page is executing at<br>
<%=Request.ServerVariables("URL")%></p>
</body>
</html>
Save the following page in the same Web folder as "Page2.asp":
<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Page 2</title>
</head>
<body>
<h3 align="center">Page 2</h3>
<p align="center">This page is executing at<br>
<%=Request.ServerVariables("URL")%></p>
</body>
</html>
Notes:- When the parent page is browsed, it will execute the second
two child pages and include their output in a table.
- When a child page is chosen in the form and submitted, only
that child page is executed.
- In each of the above cases, all pages list their URL as the
parent page's URL, because they are executing within the scope of
the parent page.
- When either of the child pages are browsed directly, they
list their respective URL as expected.
For more information, please see the Microsoft Scripting
Technologies Web site.
Additional query words:
iis ssi asp
Keywords :
Version : winnt:5.0
Platform : winnt
Issue type : kbinfo