Is there an easier way to make the classic ASP "relative path"?

I have problems right now. First of all, I have a page, let me call it "http://blah.com/login".

This obviously goes towards "index.asp"

Main.asp line:

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

The top of the page includes everything I need for my menu ... like this:

Part of the /menu.htm resource:

<div id="colortab" class="ddcolortabs">
<ul>
<li><a href="main.asp" title="Main" rel="dropmain"><span>Main</span></a></li>

...

</ul>
</div>
<!--Main drop down menu -->
<div id="dropmain" class="dropmenudiv_a">
<a href="main/announcements.asp">Announcements</a>
<a href="main/contacts.asp">Contact Information</a>
<a href="main/MeetingPlans.asp">Meeting Plan</a>
<a href="main/photos.asp">Photo Gallery</a>
<a href="main/events.asp">Upcoming Events</a>
</div>

Let's say I click on the "Ads" link (http://blah.com/login/main/announcements.asp) ... Now I'm on the ads page! But wait, I am including the same menu file. Guess what happens: I go to the site http://blah.com/login/main/main/announcements.asp which does not exist ...

: include_sub.asp . ... , ... , "menu.asp" "menu_sub.asp"? "/main/announcements.asp" , -, .

+3
5

. .

  • include, DIM , info.asp
  • info.asp DIM , strRelativePath, ""
  • info.asp asp menu.asp.
  • menu.asp <% = strRelativePath% > URL-
  • asp strRelativePath :

<!--#include file="includes/info.asp"-->
strRelativePath = "Login/"
<!--#include file="resource/menu.asp"-->
+2

menu.asp:

    Function GetApplicationPath()
        GetApplicationPath = Mid(Request.ServerVariables("APPL_MD_PATH"), Len(Request.ServerVariables("INSTANCE_META_PATH")) + 6) & "/"
    End Function

    Dim prefix: prefix = GetApplicationPath()

menu.asp, :

<a href="<%=prefix%>main/announcements.asp">Announcements</a>  

, , ASP-.

+3

, , :

Function ToRootedVirtual(relativePath)
    Dim applicationMetaPath : applicationMetaPath = Request.ServerVariables("APPL_MD_PATH")
    Dim instanceMetaPath : instanceMetaPath = Request.ServerVariables("INSTANCE_META_PATH")
    Dim rootPath : rootPath = Mid(applicationMetaPath, Len(instanceMetaPath) + Len("/ROOT/"))
    ToRootedVirtual = rootPath + relativePath
End Function

:

ToRootedVirtual("/")

ToRootedVirtual("/index.asp")

... .

+1

Virtual File, Virtual , , File.

:

  <!--#INCLUDE VIRTUAL="/resource/menu.asp"-->

, , IIS , . : http://tech.mikeal.com/blog1.php/server-side-includes-for-html-in-iis7

0
source

This can be fixed using the basic HTML tag:

Add this tag to the top of each page:

<base href="http://blah.com/login">
0
source

All Articles