次の方法で共有


Controlling IIS Application Flow

One of the primary choices of any application design is the pattern of execution. In a well-designed application, the logic of converting inputs to outputs by using modular processing units is obvious. The COM architecture and Active Server Pages (ASP) address this need for modular design to control the flow of execution in multi-tier application design.

ASP provides six different ways to affect the general flow of execution. These six methods are depicted in the following diagrams. The arrows in the diagrams represent the flow of execution. Some of these methods are available in different forms in ASP.NET, COM, and ISAPI.

Redirecting

The following illustration shows how a redirect initiates a new request from the client.

Redirection in Classic ASP

Redirection is the process of diverting a request to another location. Redirecting requires a new request to be sent to the server. However, in general, you should design your application to minimize the amount of communication between the client and server. Many design problems that have been addressed by redirecting in the past can now be accomplished by transferring, which does not initiate a new request. See Coordinating Client and Server Processing For more information about this aspect of application design.

You can accomplish redirecting by using the Response.Redirect method.

Transferring

The following illustration shows how a transfer occurs from one ASP page to another on the server.

Transferring Control in Classic ASP

The ability to transfer a request from one ASP page to another was introduced in IIS 5.0. Transferring is similar to redirecting; however, it does not require that a new request be initiated. This is a much more efficient way to control application flow. If you transfer the request to an ASP page outside of the application boundary, the boundary will be temporarily extended to include the external ASP page. The external ASP page will behave as if it were included within the application boundary of the calling ASP page. Therefore, any objects or variables that have been given application scope will still be available in the ASP page to which you have transferred. In addition to being faster than redirecting, transferring preserves all of the ASP built-in objects from the original request, including form values from an HTTP post.

You can accomplish transferring by using the Server.Transfer method.

Executing

The following illustration shows how a call to Server.Execute temporarily redirects program flow to another file.

Executing Script in Classic ASP

The ability to execute a particular ASP script and return the result was introduced in IIS 5.0. Executing is similar to a procedure call in most programming languages. This method of application flow control is appropriate if you have developed an ASP application that accomplishes some function that you want to incorporate, but have not built that function into a component.

You can accomplish executing by using the Server.Execute method.

Component Invocation

The following illustration shows how calling a component invokes compiled code during the processing of an ASP page.

Invoking COM Components in Classic ASP

This is probably the most common way to control the flow of an application. The COM programming model is integral to the Windows DNA, and should address the vast majority of design problems. Script Components, a technology supported in IIS, make it easier to take existing scripts and convert them to components.

You can accomplish component invocation by using the Server.CreateObject method. For more information on script components, see Windows Script Components and Using Components and Objects.

Exiting

The following illustration shows how the processing of an ASP can be interrupted by exiting.

Exiting a Script in Classic ASP

Under normal circumstances you will want your ASP application to complete each line of script in the page. There may be some circumstances, however, where you will need to simply end the response. For example, if you have detected (by using the Response.IsClientConnected method) that the client is no longer waiting for a response, you will want to terminate the ASP application.

You can accomplish exiting the ASP by using the Response.End method.

Procedural Processing

The following illustration shows how the processing of an ASP can be interrupted by exiting.

Executing Procedures in Classic ASP

If you want to define subroutines or functions within your .asp file, you can do so by using the procedure syntax that is appropriate for the scripting language you are using. For example, VBScript defines subroutines with the Sub ... End Sub syntax and functions with the Function ... End Function syntax. JScript, on the other hand, supports procedural processing through function calls. For more information about subroutine processing, see Writing Procedures.

Note

To ensure that IIS processes ASP code blocks in the proper order, do not use more than one language in a single page, and do not mix functions in ASP code with functions in <SCRIPT> tags in a single page.