Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



Using Server-side Includes


A server-side include directive is used 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:

<!--#INCLUDE VIRTUAL|FILE="filename"--> 

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:

<!--#INCLUDE FILE="Headers/header1.inc"-->
Note icon Note 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.

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.

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.

Note icon Note The ASP Server caches the contents of ASP pages and the pages they include (known as include files). In previous versions of Sun ONE ASP (Sun Chili!Soft ASP), once an ASP page with include files had been cached, the only way to refresh it was to change the top ASP page or reset the ASP application. This functionality has changed. Now, when an include file is changed, the ASP Server automatically refreshes the cache the next time the file is accessed.
Note icon Note Do not use an @LANGUAGE directive in a server-side include unless you are certain that an @LANGUAGE directive has not been used in the parent file. The existence of two @LANGUAGE directives could produce an error.

See also:

Creating the Basic ASP Application

Creating an ASP Page

Using @Directives



ContentsPreviousNextIndex