Groups | Blog | Home
all groups > asp.net > february 2006 >

asp.net : Application root


Arthur Dent
2/27/2006 9:33:15 PM
Why do you not want to use ~ ?


[quoted text, click to view]

Brian
2/27/2006 11:12:03 PM
Outside of ~, does anyone have tips on handling directory structure? I'm
considering adding a parameter in web.config called rootDirectory then
tacking it to relative paths as needed.

Any problems with this?

Thanks,
Brian

Brian
2/28/2006 12:00:00 AM
Well, I'm not quite sure. I don't understand the entire virtual path thing.
But from what I understand, ~ works in preprocessing but not in html. So
css, images, etc are left broken.

The immediate concern is to address the VS 2005 developer server. It runs
the project not from / but from /$(project)/ The project name must be
inserted into every URL. There are workarounds. One suggestion on the net
invoked the developer server executable with arguments to run the project as
the root url. IIS is always a choice. But I'd rather handle it in the
developer server.

Another concern is the portability of the site should it move to a new
location.

[quoted text, click to view]

Arthur Dent
2/28/2006 11:29:33 AM
Well, in my experience the ~ resolves exactly like you need, to / (if your
project is the default site) or to /yourProjectName/ (if it is a
sub-directory).
This is a runtime resolution, so if you move the site, it will still work. I
HAVE seen some weird things with rendering of ~ in FireFox in (forexample)
the NavigateUrl
property of the HyperLink control (why, i dont know, never bothered to debug
for firefox). That was 2003 though, havent tried to recreate in 2005.

For html elements such as images, it is actually pretty easy to work
around.... you could do one of two things....
write your image as either of the following:
<asp:image id=myImage runat=server imageurl="~/images/myImage.gif" />
or
<img src='<%= ResolveUrl("~/images/myImage.gif") %>' />

As a result of the ASP/FireFox rendering bug above, i have some code which
dynamically generates the full url for the approot
(essentially the same idea as ResolveUrl("~")). If you would like that code,
email me, and ill send you the code,
but like i said above, it may not be necessary anymore in 2005.


[quoted text, click to view]

AddThis Social Bookmark Button