I saw a similar question to this, but mine is slightly different:
I'm get intermittent results with #include files working on an IIS 7.5 server (R2008 V2). My includes are only working if they are in the same folder as the current .asp page, or in a subfolder of the current page. This is inconvenient, as I'd like to keep them all in a /lib subfolder, off of the main page.
My configuration: I have a folder named DCN, sitting right below the wwwroot folder. There are several files in a /lib folder within the DCN folder, so the absolute path is c:\inetpub\wwwroot\dcn\lib\my_include_file.asp. If I open an ASP page in the DCN folder, I can pull include files from the /lib subfolder. However, if I open an ASP page from the DCN/trouble folder (such as "DCN\Trouble\Search.asp"), and the search.asp page has a line that says:
<!--#include file="../lib/my_include_file.asp"-->
the include fails, and I get a 500 error.
I've also tried:
<!--#include file="/lib/my_include_file.asp"-->
with the same results. Same with:
<!--#include file="/DCN/lib/my_include_file.asp"-->
I changed the slashes to backslashes, with the same results. I even went so far as to try:
<!--#include file="c:\inetpub\wwwroot\dcn\lib\my_include_file.asp"-->
(out of sheer desparation), but am still getting the same results.
If I create a subfolder in the dcn\trouble folder, I can include files from it, but obviously, this is not ideal.
Any suggestions would be greatly appreciated. I can't help but think this is something trivial. Thanks in advance!
Yots is correct, it sounds like parent paths are turned off. If you can't get these turned on the use virtual paths instead:
Based on your question where you state that the include files are in /DCN/lib
then do the following:
<!-- #include virtual="/DCN/lib/my_include_file.asp -->
When using virtual paths you must specify the full virtual path to the file i.e. from the root of the site. This isn't ideal if you're building your application in a subfolder on your development machine where you're using XP and then deploying into the root of a production machine. That said IIS7 on Vista or Windows 7 permits the creation of multiple sites now **.
When using a path type of File="..."
, filename must be on a relative path to the folder containing the #include. For example:
The directive <!-- #include file="my_include.asp" -->
will include my_include.asp
from the same folder.
The directive <!-- #include file="lib/my_include.asp" -->
will include my_include.asp
from the folder lib
below the current folder where the script is running.
The directive <!-- #include file="../my_include.asp" -->
will include my_include.asp
from the folder lib
above the current folder (the parent folder) where the script is running.
The directive <!-- #include file="../lib/my_include.asp" -->
will include my_include.asp
from the folder lib
that is a child of the parent folder (or the current folder's sibling).
The last two examples won't work if parent paths are not enabled.
** I am aware there are hacks to enable multiple IIS sites in XP's IIS5.1.