referencing images with full path such as /images/header/left.gif

Ok, I need to know what is the best standards and practice for the following scenario. Note -- I've been developing web sites since 1996 and have developed a certain set of workarounds with each environment since VS 2002; however 2005 still exposes the same issue.

When creating a web project, VS2002-2003, the default is to create a virtual application root off your existing IIS. So your are testing your web application, you load URL as follows:

http://localhost/AppName/homepage.aspx

The problem resides when referencing global images; I have a designer work on a template and since the template can be loaded or used anywhere throughout the site (nested directories), the src= for these images must be absolute for the loading to be transparent:

<img src="/images/spacers/white_dot.gif">

I know I have the option to convert the image tag to runat="server" and made the src as = "~/images/spacers/white_dot.gif">....but to do this with all the designer image tags is quite tedious and to ask the designer to do it is also tedius. Furthermore, on other image tags such as <td runat="server" background="~/images/..." this will not work and ASP.NET will simply ignore the "~" and render the tag as <td background="~/images/...>

So, building applications intended to be hosted on URLs such as:

http://www.XYZ.com

with default development URLs such as:
http://localhost/XYZ/

turns out to be problematic either at design or at deployment.

The various solutions I have found are as follows and I am wondering if there is yet a better way of handling this situation with VS 2005.

A - With VS2002 & VS2003, I would simply modify my IIS settings to point to a different wwwroot per website (or application) and develop against the default application (e.g.http://localhost ). I have been doing this so long now, I even created a small app to help me manage the IIS settings automatically with a click.

B - hardcode the image URL's with /AppName/images so I get a good design time experience, then process these pages with a build script removing the src="/AppName/images" prefix and leaving src="/images"

Other things attempted just in case....
A - using mapped URL's such as:
<urlMappings>
<
addurl="~/images"mappedUrl="/images/"
/>
</urlMappings>

however, this didn't work..and I honestly didn't expect it to work also.

With VS2005, default apps continue to have the extra folder appended to the localhost if I choose to develop a site on the filesystem.

IDEAL SOLUTION WITH VS2005
After some investigation, the ideal solution would be to put an option on the site properties specifying whether application should use default application or not. Since VS2005 has the built in web server instance using a random port number, this solution would be trivial to implement and the default application -- hence, the URL would behttp://localhost:1234/which would work great.

[3687 byte] By [Mike95] at [2008-1-29]
# 1
I usually use a combination of the <base tag and do not specity <img src="/bleah but instead <img src="bleah.
also the (Control).ResoluveUrl method can be extremely handy also.

MarcD at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
There's probably another bunch of solutions to this problem. One option that comes to mind is to add another virtual directory which points to the image folder, and use that one from the root of the web application.
Of course you could get into problems when you have multiple applications running from virtual direcories which use this same approach.
This same problem could arise using the 'IDEAL SOLUTION WITH VS2005' when you do want to run the web application from a virtual directory.


CJ_S at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
Yes, but some application are meant to be run as a virtual application while others are made to run as a default application and we should be able to work with both in VS. Hopefully someone from the VS.NET team reads this and makes a point in introducing this option in VS2005.
At the office here, another member solved the image reference by introducing the /images/ virtual folder on his local IIS, however this has various conflicts with default applications which have their own /images folder (e.g. removing the virtual folder when working on a default application, etc.).
You mention "another bunch of solutions"...I'm interested in reading what else you have to suggest.
Mike95 at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4
Ok, I believe we have a communications problem here. In a nut shell, when creating websites in the past we were able to have virtual directories within web sites that point to the same physical location, mainly to save on space for images and such.

now with VS2005 and virtual webs we want to know how to be able to do the same thing.

AngeloCook at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified