Search code examples
asp-classicincluderelative-pathinclude-pathdocument-root

Relative path for a included file - ASP/HTML


Sorry if this question is answered somewhere else but I tried searching several pages and was unsuccessful.

So i have an include file (sidebar) which i am using in all pages.

Default.asp
Products.asp
Salary/Survey.asp
inc/sidebar.asp (this is the included file)

now inside sidebar.asp I have a link for Salary/Survey.asp

from all other pages at root level, i can simply use href='Salary/Survey.asp' and will work fine. but when I am on page Survey.asp , writing href='Salary/Survey.asp' will become actually Salary/Salary/Survey.asp. I understand it has to be ../Salary/Survey.asp to be used properly but it will then not work for root level pages.

I can not use root relative which is /Default.asp and /Salary/Survey.asp as I am working for someone else' project and i dont know his directory structure and thus i only have option to document relative path.

Hope this is clear to understand and someone helps me out.

Thanks!


Solution

  • We solved this problem the following way...

    1. Each of our asp pages included a special file that Dims and sets golbal variables. We called ours Info.asp
    2. Inside Info.asp we defined a variable called strRelativePath
      Dim strRelativePath
      strRelativePath = ""
    3. Every asp page set the relative path according to it relative position:

    for example:

    • Root pages - strRelativePath = ""
    • One level deep pages - strRelativePath = "../"
    • Two levels deep pages - strRelativePath = "../../"

    Then it was a matter of prefacing all the links requiring a relative path with <%=strRelativePath%>