As more people use Active Server Pages, I've noticed a trend that newer users can't figure out how to include files into their scripts. Part of the problem is that they expect an include directive to exist in the '<%' and '%>' script tags, but this isn't the case with Active Server Pages. Instead, you'll notice the include directive is reminiscent of Apache, or other web servers that allow server-side includes. As such, there are some rules to including files and keeping them from breaking your script that you have to keep in mind. So let's jump right in...

To include files in ASP pages:

<!--#include virtual file ="filename"-->

The 'virtual' and 'file' keywords indicate the type of path you are using to include the file, and 'filename' is the path and file name of the file you want to include.

Included files do not require a special file name extension; however, MS docs will recommend giving included files an .inc extension to distinguish them from other types of files. I prefer to create a directory that contains all the files, and give them all an .asp extension. If someone finds that directory and/or file name (which can happen if your ASP scripts break and it shows the offending code), then the ASP parser will execute the script within. By default, the server will treat an .inc file as plain text and serve it as such. Often my include files are functions or navigation, so the result is a blank screen or an odd HTML page if I use an .asp extension. This prevents a user from seeing my code (which may include database connection information), and while it may generate an error, this is preferrable to showing all my script as plain text.

Using the 'Virtual' Keyword

Use the 'virtual' keyword to indicate a path beginning with a virtual directory. For example, if a file named '' resides in a virtual directory named '/footer,' the following line would insert the contents of '' into the script containing the line:

  <!--#include virtual ="/footer/"-->

Using the 'File' Keyword

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 'headers', and the file '' is in 'root\headers', the following line would insert '' into your script:

  <!--#include file ="headers/"-->

Note that the path to the included file, 'headers/,' is relative to the including file; if the script containing this #include statement is not in the directory '/root', the statement would not work.

You can also use the file keyword with '../' syntax to include a file from a parent, or higher-level, directory if the 'Enable Parent Paths' option is selected in Internet Service Manager.

Other Notes: