
Originally Posted by
Wes DeMoney
I would like to see what some of the anti parent path people think.
Is that a hint?! 
Clearly in situations where you need to be able to place a set of scripts at any place or level in a web site's folder structure and have them work straight off, using webroot-relative paths is a no-no. In such situations then the only clean solution *is* to use relative links as you suggest.
Of course, as we (should) all know, you can't dynamically include scripts, and although you can Server.Execute or Server.Transfer to them, they then execute within their own scope, which makes their use severely limited.
That said I have come up with one sneaky way to (sort of) get round this problem, but it only applies if the app will *always* be installed in a subfolder of the webroot (i.e. a direct descendant) AND the user wants to change the name of this subfolder (e.g. from "/wesblog/" to "/blog/").
What the user should do is install the scripts into the normal /wesblog/ folder, create a virtual folder called "/blog/" which points to the "/wesblog/" folder, then finally remove world-readable permissions to the "/wesblog/" folder from within the IIS snap-in. Then the app will only be available as "http://servername/blog", but the scripts themselves will still be able to use the root-relative paths to include other scripts within the "/wesblog/" subfolder hierarchy.
Please note that this only solves the server-side problem... root-relative links that will be parsed by the browser (i.e. IMG SRC attributes, A HREFs, etc.) will be broken, because they will attempt to access the folder which is no longer world-readable, instead of the virtual folder. However, since the links in the HTML *can* be constructed dynamically, this could be fixed by using a global/application variable to prefix each path with the location of the virtual folder, like so:
Code:
<img src="<% = WesBlogVirtualPath %>icon.jpg">
where WesBlogVirtualPath is elsewhere set equal to "/blog/", to continue with the example that I have used throughout this post.
It's not a very satisfactory approach, but it is an alternative one. However, I think in such a situation, using relative paths would be acceptable.
And with that, I'm off to bed! ZZZZzzzz....
Bookmarks