Include File Path problems

Posted on 2005-04-08
Last Modified: 2013-11-18
Hi all,

I am working on a menu that needs to be included in all the pages of my website.

At this time, the structure of my site is as follows:

Root: menu.asp, index.asp, header.asp etc....

Then, subfolders: let's say Folder1. And in Folder1 asp pages that include the header located in the root.

My header code (header.asp) is like this:

<table cellpadding="0" cellspacing="0" width="743" align="center" height="123">
     <td align="center" width="743" height="123" background="">
   <tr><td><!-- #include file = "menu.asp"--></td></tr>

I include the header in all of my pages like this at the top of each pages:

<body class="body">
  <table class="maintable" align="center">
      <tr width="740" height="120" >
          <td colspan="3"><!--#include file="Header.asp"--></td>


Now without the menu.asp include, everything works fine. The logo is included in each file since I'm using the absolute path to the image.

But my menu is only properly included in the index page. On any other subpages located in subfolders, the menu does not appear. I'm sure it's because the ../../ are screwed up because of the include, but is there anyway around this?

And maybe it's a javascript path problem. My menu.asp is like this:

<!-- menu script itself-->
<script language="JavaScript" src="menu.js"></script>
<!-- links are stored there -->
<script language="JavaScript" src="menu_items.js"></script>
<!-- styles structures -->
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
    new menu (MENU_ITEMS, MENU_POS);

thanks in advance!
Question by:ThePrince
    LVL 18

    Accepted Solution

    You may have better results with this:

    <!--#include virtual="Header.asp"-->
    <!--#include virtual="menu.asp"-->
    LVL 18

    Expert Comment

    When you use "file" rather than "virtual", the path to the include is relative to where the included content ultimately displays...

    So if you have files located at different levels, it's difficult to have includes calling other includes when you use "file" and not "virtual"...

    Note that the folder that contains the include being called via "virtual" must actually be a virtual folder. But this is usually the case with your web root, so you should be ok.
    LVL 13

    Expert Comment

    when you include file header.asp into myfile.asp in the subfoler

    subfolder myfile.asp
    root header.asp

    header.asp and its contents become with the same level with myfile.asp on the sub folder

    and it will look for the menu.js etc... in the subfolder directory

    LVL 18

    Expert Comment

    If my first suggestion doesn't work, try adding an "Includes" folder in your root. Then try the following:

    <!--#include virtual="Includes/Header.asp"-->
    <!--#include virtual="Includes/menu.asp"-->

    You may need to define a new virtual folder in IIS that points to the Includes folder.
    LVL 13

    Expert Comment

    SquareHead's solution is better i think :)

     you may create a subfolder "menu"

    and put the header files in it

    root folder
       MENU (folder)
          etc ...

    ---- menu.asp ---
    <script language="JavaScript" src="../menu/menu.js"></script>
    <!-- links are stored there -->

    also for images give the path like "../menu/"  upto one level then into menu folder

    subfolder (subpage.asp)
     <!-- #include file="../menu/menu.asp" -->

    root folder (index.asp)
    <!-- #include file="menu/menu.asp" -->

    LVL 7

    Expert Comment

    For javascripts and images you can force the browser to request the files from the root by placing a / at the start of the filename or path.

    <script language="JavaScript" src="/menu/menu.js"></script>
    <td align="center" width="743" height="123" background="/images/logo/logo.gif">

    I'm pretty sure this works for INCLUDE files too so try

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

    LVL 14

    Expert Comment

    Things I would change to Garve's response...

    language= is deprecated for client-side javascript, use type= instead.
    <script type="text/javascript" src="/menu/menu.js"></script>

    See deprecate:

    include 'file' cannot start at root using / but include 'virtual' can.
    <!--#include virtual="/menu/menu.asp"-->

    However I agree with his approach and do this explicitly and never have session issues as you're experiencing.
    LVL 18

    Expert Comment

    @ThePrince -- any update on this?
    LVL 6

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
    I will leave the following recommendation for this question in the Cleanup topic area:
    Split: SquareHead & nurbek & Garve

    Any objections should be posted here in the next 4 days. After that time, the question will be closed.

    EE Cleanup Volunteer
    LVL 14

    Expert Comment


    If you use Garve's suggestion, you'll get an error:

    Active Server Pages error 'ASP 0130'

    Invalid File attribute

    /menu/menu.asp, line #

    File attribute '/menu/menu.asp' cannot start with forward slash or back slash.

    However, putting everything in the menu folder is the best idea to keep everything together and use VIRTUAL to access it.

    There is never a reason to parent paths unless your paths are so long that it would truncate do to the limit of the URL.  Also, parent paths should be disabled for security reasons.

    I don't know why you left me out of the split but I would split between Garve any myself.  He had the right idea, just the wrong syntax.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now