You use a server-side include directive to import a file into an ASP page during processing. Any text file can be imported, or "included." The contents of the included file are placed on the page at the location of the server-side include directive.
You can include files that themselves contain included files. In the event of a "loop," in which the first file contains an included file that in turn includes the first file, ASP reports an error. Included files can also be ASP files; the results of an included ASP file are placed at the position of the #include statement. You cannot build a server-side include statement programmatically because ASP processes #include directives before processing any script.
The syntax for a server-side include is as follows:
To specify the path, use the virtual keyword to indicate a path name beginning with a virtual directory. Use the file keyword to indicate a relative path name that begins with the directory containing the include file. For example, if a file is in the directory Dir1, and the file header1.inc is in Dir1/Headers, the following code would insert header1.inc in your file:
If the EnableParentPaths configuration setting is set to yes, you can also use the File parameter with ../ syntax to include a file from a parent (higher-level) directory. By default, EnableParentPaths is set to no. In this case, the CreateObject ("Scripting.FileSystemObject") calls generated in the global.asa file by FrontPage do not work. Your system administrator must change EnableParentPaths to yes, or you must change the code generated by FrontPage in the global.asa file to Server.CreateObject ("Scripting.FileSystemObject"). For more information, see "Configuring File System Access" in "Chapter 3: Managing Sun Chili!Soft ASP."
There is no real performance penalty for using server-side includes. ASP saves files in memory in a compiled form after processing them. Processing only occurs the first time a file is accessed.
Often after you edit an "included" file, the change does not show up in your ASP page. The ASP Server only picks up changes in an included file if it recompiles the page that contains the #include directive. You can force a recompile of this page by "touching" the file or by making a trivial change that updates the timestamp on the file.
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.
Creating the Basic ASP Application in this chapter
Creating an ASP Page in this chapter
Using @ Directives in this chapter
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.