About Include in ASP

zhaozj2021-02-16  97

Contain files

The SSI instruction provides the user with a method of inserting a file into another file prior to the web server processing. ASP only uses the #include directive of this mechanism. To insert a file in the .asp file, use the following syntax:

Virtual and File Keywords indicate the type of path to contain the file, FileName is the path and name of the file you want to include.

The included file does not require a dedicated file extension; however, it is a good program habit to configure the .inc extension to be included in the included file to distinguish between other types of files.

Use virtual keywords

Use the Virtual keyword to point out the path start in the virtual directory. For example, if a file named footer.inc is a virtual directory named / myApp, the following line will insert the contents of the FOOTER.INC into the file containing the row:

Use the file keyword

Use the File keyword to indicate the relative path. The relative path begins with a directory containing the included file. For example, if your file is in your directory myApp, and the file header1.inc is in MyApp / Headers, the following line will insert Header1.inc into your file:

Note that the path to the included file headers / header1.inc is relative to the included file; if the script containing the #include statement is not in the / myApp directory, then the statement will not work.

If you select the "Enable Upset" option in the Internet Service Manager, you can also use the File keyword and .. / syntax contains files in the previous directory.

Position containing files

The included files can be outside your Web site in a directory in your Web site. Typically, you should make the included files in the directory of the Web site. If an included file is within your Web site, the change in the included file will be displayed when the browser requests the file next time. However, if the included file is located outside your Web site until the ASP application restarts or the web server restarts, this change can be reflected. ASP detects changes in any included files in the application namespace (in the initial directory of the application).

Contains files: Tips and warning

An included file can also contain other files. If the #include instruction does not cause a loop, one .asp file can include the same file multiple times. For example, if the file first.asp contains file second.inc, second.inc must no longer contain first.asp. A file cannot contain itself. ASP detects such cyclic or nested errors and generates an error message while detecting, while stopping processing the requested .asp file.

ASP contains files before performing the script command. Therefore, the name of the included file cannot be created with a script command. For example, the following script will not open Header1.inc because the ASP will execute the #include instruction before it assigns a file name to the variable name.

<% Name = (Header1 & ".inc")%>

" -> The script command and process must be fully included in the script delimiter <% and%>, HTML tag