469,643 Members | 1,833 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Absolute Pathing Challenge

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\mymenusc ript.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



Jul 19 '05 #1
9 3493
"Stuart" <st***********@insurity.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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").
Note, that is a relative path, NOT an absolute path. It is relative to the
root of the webserver (as specified by the leading /).
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\mymenusc ript.js
I'm not sure what exactly it is you are asking for? Is there a file at this
location?
c:\inetpub\wwwroot\MySubWeb\_scripts\menu\mymenusc ript.js
If so, then you don't need to do anything. Your ASP looks correct.

Or do you want this to also point to:
c:\inetpub\wwwroot\_scripts\menu\mymenuscript.js

In that case, you must not include the sub folder name in the path. This
would look exactly the same as your first example, since you are pointing to
a file that is relative to the root of the website.
mappath("/_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" -->


To what? What is it that you want?

Peter Foti

Jul 19 '05 #2
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.
"Peter Foti" <pe****@systolicnetworks.com> wrote in message
news:vq************@corp.supernews.com...
"Stuart" <st***********@insurity.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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").


Note, that is a relative path, NOT an absolute path. It is relative to

the root of the webserver (as specified by the leading /).
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\mymenusc ript.js


I'm not sure what exactly it is you are asking for? Is there a file at

this location?
c:\inetpub\wwwroot\MySubWeb\_scripts\menu\mymenusc ript.js
If so, then you don't need to do anything. Your ASP looks correct.

Or do you want this to also point to:
c:\inetpub\wwwroot\_scripts\menu\mymenuscript.js

In that case, you must not include the sub folder name in the path. This
would look exactly the same as your first example, since you are pointing to a file that is relative to the root of the website.
mappath("/_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" -->


To what? What is it that you want?

Peter Foti

Jul 19 '05 #3
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

"Peter Foti" <pe****@systolicnetworks.com> wrote in message
news:vq************@corp.supernews.com...
"Stuart" <st***********@insurity.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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").


Note, that is a relative path, NOT an absolute path. It is relative to

the root of the webserver (as specified by the leading /).
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\mymenusc ript.js


I'm not sure what exactly it is you are asking for? Is there a file at

this location?
c:\inetpub\wwwroot\MySubWeb\_scripts\menu\mymenusc ript.js
If so, then you don't need to do anything. Your ASP looks correct.

Or do you want this to also point to:
c:\inetpub\wwwroot\_scripts\menu\mymenuscript.js

In that case, you must not include the sub folder name in the path. This
would look exactly the same as your first example, since you are pointing to a file that is relative to the root of the website.
mappath("/_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" -->


To what? What is it that you want?

Peter Foti

Jul 19 '05 #4
"Stuart" <st***********@insurity.com> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
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?


Yes it does. This sounds like a problem that I had not too long ago. My
situation involved secure pages, where the unsecure version could be
accessed like this:
http://www.mysite.com/myfile.htm
and the secure version of the page could be accessed like this:
http://secure.myISP.com/mysite/myfile.htm

I had been declaring all of my includes, images, scripts, and style sheets
relative to the root, but then when I tried to access them securely, this
was a problem because now the path to those files was actually
"/mysite/myfiles" instead of "/myfiles".

Unfortunately, I was never able to get a solution for this problem. I
thought about doing what you mentioned (using some ASP variable in the
links, etc.), but that doesn't work for includes since they are processed
first. Ultimately, I decided that I didn't need to access my secure pages
over an unsecure connection, so I ended up with 2 methods. For non secure
pages, included files were relative to website root ("/"), and for secure
pages, included files were relative to the website root plus my subdirectory
("/mysite/"). You can probably still find the thread in
comp.infosystems.www.authoring.site-design.

I hope this helps (but I don't think there's a solution to your problem...
if there is, I'd love to see it posted here). :)

Regards,
Peter Foti
Jul 19 '05 #5
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).

--
Cheers!
SiteGuru
http://www.siteguru.co.uk

"Peter Foti" <pe****@systolicnetworks.com> wrote in message
news:vq************@corp.supernews.com...
"Stuart" <st***********@insurity.com> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
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?


Yes it does. This sounds like a problem that I had not too long ago. My
situation involved secure pages, where the unsecure version could be
accessed like this:
http://www.mysite.com/myfile.htm
and the secure version of the page could be accessed like this:
http://secure.myISP.com/mysite/myfile.htm

I had been declaring all of my includes, images, scripts, and style sheets
relative to the root, but then when I tried to access them securely, this
was a problem because now the path to those files was actually
"/mysite/myfiles" instead of "/myfiles".

Unfortunately, I was never able to get a solution for this problem. I
thought about doing what you mentioned (using some ASP variable in the
links, etc.), but that doesn't work for includes since they are processed
first. Ultimately, I decided that I didn't need to access my secure pages
over an unsecure connection, so I ended up with 2 methods. For non secure
pages, included files were relative to website root ("/"), and for secure
pages, included files were relative to the website root plus my

subdirectory ("/mysite/"). You can probably still find the thread in
comp.infosystems.www.authoring.site-design.

I hope this helps (but I don't think there's a solution to your problem...
if there is, I'd love to see it posted here). :)

Regards,
Peter Foti

Jul 19 '05 #6
"SiteGuru" <sa***@siteguru.co.uk> wrote in message
news:3f**********************@news.dial.pipex.com. ..
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).


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.

Peter
Jul 19 '05 #7
On Wed, 5 Nov 2003 16:26:54 -0500, "Peter Foti"
<pe****@systolicnetworks.com> wrote:
"SiteGuru" <sa***@siteguru.co.uk> wrote in message
news:3f**********************@news.dial.pipex.com ...
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).


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
Jul 19 '05 #8
"Jeff Cochran" <jc*************@naplesgov.com> wrote in message
news:3f****************@msnews.microsoft.com...
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 -->


No, that does not work because the include statement is processed before any
ASP gets processed.

Peter

Jul 19 '05 #9
"Jeff Cochran" <jc*************@naplesgov.com> wrote in message
news:3f****************@msnews.microsoft.com...
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 -->


Interestingly enough, I think I have found the solution to this problem:
http://www.aspfaq.com/show.asp?id=2042

Peter
Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by clintonG | last post: by
8 posts views Thread by Frank Buss | last post: by
reply views Thread by Richard Jones | last post: by
3 posts views Thread by Thierry | last post: by
reply views Thread by Richard Jones | last post: by
13 posts views Thread by lawpoop | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.