Absolute Pathing Challenge

S

Stuart

Hi All,
I got a challenge to make the same APS/Script/Html run on different web
roots. I can not use relative pathing in a lot of cases. We use lots of
included files so depending on where that file is running, the pathing in
those included files varies. So we do a lot of absolute pathing.
Example: Instead of Mappath("../../../_scripts/menu/mymenuscript.js") we use
mappath("/_scripts/menu/mymenuscript.js").

In one case, the code is loaded right on wwwroot with all the folders off of
wwwroot.
So a path like so mappath("/_scripts/menu/mymenuscript.js") would return
c:\inetpub\wwwroot\_scripts\menu\mymenuscript.js

In another case, the SAME code has to run under a subweb, so we would have
to include the subweb name like so.
mappath("/MySubWeb/_scripts/menu/mymenuscript.js") would return
c:\inetpub\wwwroot\MySubWeb\_scripts\menu\mymenuscript.js

So how do you solve this.
With ASP pages, I could detect where I'm running in the global.asa and set a
APP variable and use that variable anywhere I'm building a path name. I
would have to modify all the HTML code etc <A
HREF='<%Application("BasePath")%>/myfolder/mywebpage.htm'>MyLink</A>
This is a pain...but doable. But that does not address a lot of the pure
HTML files or included script files in the ASP pages or Included ASP files..

Examples:
How would I change an ASP include file.
<!--#INCLUDE Virtual ="/Includes/MyAsp.asp" -->

Or a JScript include like this
<script type="text/javascript" language="javascript"
src="/_scripts/MainMenu/MyMenuScripts.js"></script>

Then there is the issue of the client side JScript having to know that
pathing info which could be in a included file like the example above.

Looking for some ideas...examples would be great too.

Thanks
Stuart
 
T

TomB

I think he wants to put the same website on a different machine in a subweb.
So all of his absolute paths are wrong. He's looking for a "simple" way of
fixing ALL of them.

The only solution I can think of off hand, is to use a find and replace
tool.

Oh wait, if you set IIS to process html files as well, then you could use
the Application("BasePath") solution. But that won't solve the Includes
problem.
 
S

Stuart

Hi Peter,
Wrong choice of words, "Virtual Path" not Absolute path begin with "/".
A Relative path will navigate to a file based on where the current running
file is in the directory structure.
MapPath("../../FolderA/SomeFile.js") is a relative path.
MapPath("/FolderA/SomeFile.js") is a virtual path....read the MapPath() info
on IIS Help.

I thought my question was pretty clear...but I'll try again.
I want the "SAME" code base to be able to run on different websites with no
changes.
In one case the code will be running on the Web Root. In another case it
will be running under a SubWeb.
I don't want to have to change all the pathing information in the code base,
I want the code to be able to figure it out.
Does this help?

Thanks
Stuart
 
S

SiteGuru

AFAIK the only foolproof way of achieving these ends is to use relative
paths. That way the paths will always be right as long as the folder/file
structure is consistent starting from YOUR root folder (i.e. the folder with
your default Home page for this application).
 
J

Jeff Cochran

Right, but the problem with that approach is that if I want to have some
base template for all of the pages in my site, then a file that was located
in:
/
could not use the same template as a file in:
/foo/
which could not use the same template as a file in:
/foo/bar/
etc.

And if I ever want to move a page from one level in the hierarchy to
another, I will need to modify that file to point to the new path relative
to the file. However, if I use a path relative to the root of the website,
then I don't need to modify any of those links.

Welcome to the world of web organization. If you want the *same* code
to run on *all* sites they need the *same* structure.

You could work around this with a base URL, possibly as a variable in
the include statement. Maybe something like this(never tried, but ten
seconds would tell you if it works):

<% BaseURL="/foo/bar/" %>
<!--#Include File="<% =BaseURL %>folder1/folder2/filename.asp -->

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top