5.5 Server-side Includes

Use Server-side includes to import other files into an ASP page during processing. The included files can be any kind of text file. The contents of the included file are treated as if it had been placed at that position in the ASP file. Include files can be nested, i.e., included files can also contain included files of their own. ASP will detect loops (files that ultimately include themselves) and report an error. Included files can also be ASP files, meaning the results of an included ASP file will be placed at the position of the #INCLUDE statement.
ASP processes #INCLUDE directives before processing any script, so it is not possible to build an include statement programmatically.
Syntax
<!--#INCLUDE VIRTUAL|FILE="filename"-->
Remarks
Use the Virtual keyword to indicate a path beginning with a virtual directory. Use the File keyword to indicate a relative path. A relative path begins with the directory that contains the including file. For example, if you have a file in the directory Dir1, and the file Header1.inc is in Dir1/Headers, the following line would insert Header1.inc in your file:
<!--#INCLUDE FILE="Headers/header1.inc"-->
If the EnableParentPaths registry setting is True, you can also use the File parameter with ../ syntax to include a file from a parent, or higher-level, directory.
Within an included ASP file, script commands and procedures must be entirely contained within the script delimiters <% and %>, the HTML tags <SCRIPT> and </SCRIPT>, or the HTML tags <OBJECT> and </OBJECT>. That is, you cannot open a script delimiter in an included ASP file, and then close the delimiter in the referencing file. The script or script command must be a complete unit.
There is no real performance penalty for using Server Side Includes. ASP saves files in memory in a compiled form after processing the includes. The include processing will only occur the first time a file is accessed.
Note:
Often, after editing an "included" file, the change will not show up in your ASP page. The ASP engine will only pick up changes in an included file if it re-compiles the page that contains the #INCLUDE directive. You can force a re-compile of this page by "touching" the file, or by making a trivial change that updates the timestamp on the file.
Copyright © 2000 Chili!Soft
|