View Full Version : Included file can not be in other dircetory, same hierarchy?
avivit
11-05-2002, 08:40 AM
I have an asp file in "a" directory and tried to include there an asp file, which is located
in "b" directory which is in the same hierarchy as "a"
(i.e. - both r sub-directories of the same dircetory).
I can't do it on the server, but does work on pws.
Is there any restriction regarding the location of the included file?
dominicall
11-05-2002, 08:53 AM
Can you the post the code you're using and a clearer description of the directory structure...
i.e. are you using <!-- #include file...... or <!-- #include virtual....
Try using
<!-- #include virtual="/rootdir/subdir/b-dir.file.asp -->
Dominic :D
whammy
11-08-2002, 12:37 AM
Someone else posted the exact same question about a month ago, and it turned out although they THOUGHT they were using the same directory structure on their local machine as the server, in reality they weren't, since they weren't thinking of wwwroot as the "root" of the application.
Check out the sticky thread I posted about ServerVariables - you can use "PATH_INFO" to see the actual path to your file (on PWS AND your live server) that way.
:)
avivit
11-12-2002, 12:51 PM
CODE I USE:
<%@ Language=VBScript enablesessionstate=false%>
<%Response.Buffer=true%>
<!--#include file="../Scripts/xxx.asp"-->
<%...
%>
<html>
<body>
........
********************************************
And in the included file I only wrote one line for test,
which should be seen as a note in html src code of
the asp page that included it.
<%
response.write("<!--reached the included page..-->")
%>
*************************
The location is right. It works for my PWS.
I also checked the directories on the life server.
But did not work there.
Anyway, I relocated the "Scripts" directory as a sub-directory of the sub-dir , so I refer it as:
<!--#include file="Scripts/xxx.asp"-->
AND IT WORKS on server too.
Why is that so?
Thanks very much
Roy Sinclair
11-12-2002, 02:40 PM
I would bet that the difference is that PWS has the "Enable Parent Paths" option is set for the application but it isn't set on the server.
whammy
11-12-2002, 04:20 PM
Also you might try using include virtual, and the path to the file using "/" as your root directory:
<!--#include virtual="/Scripts/xxx.asp"-->
avivit
11-13-2002, 07:16 AM
Roy, could be. I am not the admin, and have no access to the live server. I only transfer the files I build to the admin and he puts them in place.
But, shouldn't I get another error msg if that was the problem? An error msg like the following?
Active Server Pages, ASP 0131
Disallowed Parent Path
The Include file '../<filename.ext>' cannot contain '..' to indicate the parent directory.
/<path>/<filename.ext>, line <number>
Thanks Roy.
Whammy, Dominicall- Thanks, I'll check it out too.
avivit
11-13-2002, 01:07 PM
I found the following quote that claims exactly what I ahd problem with:
"People tend to a mistake with include file, regarding the difference between:
<!--#INCLUDE VIRTUAL="head.asp"-->
and
<!--#INCLUDE FILE="head.asp"-->
When you use the key word VIRTUAL you say to ASP that the file you want to include is located in the root dir of your web server, if you use the FILE key word you tell ASP that the file to include is located in the SAME directory as the ASP file you have the include statement in. "
I used a sub-directory and works as well, but can not include from another directory from root (while my directory is also from root).
Thanks
whammy
11-13-2002, 11:38 PM
Yes, you can:
<!-- #include virtual="/subfolder/filename.ext" -->
will work from anywhere, since the first "/" is your root folder. That will even work in your root folder.
Likewise, including something in your root folder everywhere you can do the same way:
<!-- #include virtual="/filename.ext" -->
:)
avivit
11-14-2002, 07:01 AM
I was quoting all, but meant the part regatding the non-virtual reference. Have never ysed virtual.
Btw - I found a note regarding the non-virtual reference:
***************************************************
"An interesting note: you can use the ../ syntax with the file keyword to include a file in a parent directory. Why is this interesting? IIS is the only webserver I've seen that allows you to do that! (Of course, I've not used many.) According to the NCSA HTTPd documentation, the #include file cannot contain ../. I guess Microsoft is just doing its own thing here. One side effect of allowing developers to use include files in parent directories is that you can include files outside of your web site!
You can only do this if you have the Enable Parent Paths turned on."
****************************************************
4guysfrom Rolla (http://www.4guysfromrolla.com/aspscripts/printpage.asp?ref=/webtech/080199-1.shtml)
Yovav
11-14-2002, 07:31 AM
Avivit U seem so smart
I bet U R from holy land :-)
Will U be my girl ?
avivit
11-14-2002, 07:36 AM
+ a baby.
Thanks
whammy
11-14-2002, 11:53 PM
:rolleyes:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.