Tutorial
#include命令用于在多重页面上创建需重复使用的函数, headers, footers, or other elements.
#include command
By using the #include command, we can insert another ASP file into this file before the server executes an ASP file. #include命令用于在多重页面上创建需重复使用的函数, headers, footers, or other elements.
How to use the #include command
Here is a file called "mypage.asp":
This is the "wisdom.inc" file:
"One should never increase, beyond what is necessary,the number of entities required to explain anything."
This is the "time.inc" file:
<%response.write (Time)%>
The source code viewed in the browser should look like this:
Syntax for including files:
To refer to the file in ASP, place the #include command in the Comment tab:
<!--#include virtual= "Somefilename"-->
Or:
<!--#include file = "Somefilename"-->
Keyword virtual
The keyword virtual indicates the path that is located in the virtual directory.
If the name "Header.inc" is in a virtual directory named/html, the following line of code inserts the contents of the file "Header.inc":
<!--#include virtual = "/html/header.inc"-->
Keyword file
The keyword file can indicate a relative path. The relative path starts with the directory that contains the referenced file.
Suppose a file is in the subfolder headers of an HTML folder, and the following code refers to the contents of the "Header.inc" file:
<!--#include file = "Headers\header.inc"-->
Note: The path to the referenced file is relative to the referencing file. This declaration is not valid if the file containing the #include declaration is not in the HTML directory.
You can also use the keyword file and syntax (... \) to refer to files in the parent directory.
Tips and comments
In the above section, we use ". Inc" as the suffix of the referenced file. Note: If a user tries to navigate directly to an inc file, the contents of the file are exposed. If the content in the referenced file involves confidentiality, it is best to use the "ASP" suffix. The source code in the ASP file is not visible when it is compiled. Referenced files can also refer to other files, and ASP files can refer to the same file multiple times.
Important: The referenced file is processed and inserted before the script executes.
The following code cannot be executed because ASP executes the #include command before assigning a value to a variable:
<%fname= "Header.inc"%><!--#include file= "<%=fname%>"-->
You cannot include a file reference between script delimiters:
<%for i = 1 to n <!--#include file= "Count.inc"-->next%>
But this script can work:
<% for i = 1 to n%><!--#include file= "count.inc"--><% Next%>