Include other files
Using the service-side include command makes it easy to include additional files in active Server pages. This service-side include command does not need to be implemented in a script, it can be a part of the HTML code.
<HTML>
<HEAD><TITLE> Welcome </TITLE></HEAD>
<BODY>
<!--#INCLUDE virtual= "Mybanner.inc"-->
Welcome to the entrance!
</BODY>
</HTML>
In this example. File Mybanner.inc will be inserted under this ASP file <BODY> tag, and when the ASP file executes, the HTML code in Mybanner.inc and the script will also be executed or appear in the corresponding location. (in fact, similar to subroutines, except that no parameters passed)
This file contains two approaches, a virtual path or a physical real path. The following is an example of the latter:
<HTML>
<HEAD><TITLE> Welcome </TITLE></HEAD>
<BODY>
<!--#INCLUDE file= "Mybanner.inc"-->
Welcome to the entrance!
</BODY>
</HTML>
If you use the file command to specify a physical path, the file must be under the current directory or subdirectory. In this example, the file is in the current directory, so the limit is more, so you should generally use the virtual path command.
This kind of file containment is effective for any extended name, and is generally used by the. Inc suffix, but as long as you're happy. asp,. htm,. html, or any other suffix is ok.
Note: When you change the included file, it does not necessarily immediately see the effect, because IIS caches, IIS responds to changes to normal files faster than the response to include file changes.
In this situation, there are two ways to handle it, one is to restart the server in Internet Service Manager. Alternatively, you can make changes to the parent file that contains other files, such as adding a meaningless space, so that IIS realizes the change and responds correctly, but it's obviously a time-consuming task if there are more parent files that contain the change file.
In two situations generally need to include other files, one is some very common common program segments or scripts, do not need to write every ASP file, then can be included in each of the required ASP files on the line (can save a lot of strength: P).
The other is the situation where the criteria are redirected, such as the example in the above section, and can be implemented entirely using the include statement. For example, look at the following example:
<%
IF Request.Form ("Username") = "" THEN
%>
<!--#INCLUDE virtual= "regester.asp" >
<%
Response.End
End IF
%>
<HTML>
<HEAD><TITLE> Registration Results </TITLE></HEAD>
<BODY>
Thank you, <%=request.form ("UserName")%> registration!
</BODY>
</HTML>
This example shows that it can have the same effect as the Response.Redirect method, and when the user does not fill in the name, it is booted back to the registered home page, but because the execution of this statement is done entirely on the server side, there is basically no compatibility problem with the browser.
It is also important to note that the execution of the include statement in IIS takes precedence over the execution of the script, which means that it will not work if the include statement is placed outside the script and waits for the script to pass the parameter. For example, the following example:
<%
IF Request.Form ("Username") = "" THEN
Myinlcude= "Register.asp"
ELSE
Myinclude= "Homepage.asp"
End IF
%>
<!--#INCLUDE virtual= "<%=MyInclude%>"-->
This script is wrong because the include statement is executed first in IIS and then the execution of the VB script. In this way, the file "<%=MyInclude%>" is naturally not found.