ASP nested includes problem

Developers often run into a problem with using ASP include files that reference other include files. This is known as nested includes. The major mistake that is made is that the developer attempts to use relative addressing for the files.

Developers often run into a problem with using ASP include files that reference other include files. This is known as nested includes. The major mistake that is made is that the developer attempts to use relative addressing for the files. Here's an example:

<!--#include file="myscripts/myinclude.asp"-->

In order for this include to be used in other includes, they must reside in the root folder of the web site. There are numerous other scenarios that are affected by this.

The solution is to create virtual directories in IIS to house your ASP include files and reference them as:

<!--#include virtual="myscripts/myinclude.asp"-->

This include file can now be nested in any number of includes regardless of where the parent include actually resides. You may also want to use root addressing for your HTML elements such as images and stylesheets. Here's and example:

Instead of <img src="images/myimages/myimage.jpg >

use <img src=/images/myimages/myimage.jpg >

This will enable the item to be referenced properly regardless of where the parent file exists on the web site.






Submission Date:  9/23/2005 2:49:43 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (608 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP