views:

16

answers:

2

I have inherited a web site that has all of the paths set using relative paths, that only work when the site is located in the web root.

I have put the site in a virtual directory, and none of the paths work correctly.

<img src="/img/logo/BadCo.gif" width="156" height="55" alt="BadCo" />

I can resolve this as follows:

<img src='<%= ResolveUrl("~/img/logo/BadCo.gif") %>' width="156" height="55" alt="BadCo" />

However, I do not want to have to manually change every single one, of hundreds of paths throughout the project, and coming up with a regex to do the replace would hurt my tiny brain.

Any ideas or suggestions will be much appreciated

+2  A: 

Personally, I wouldn't have put the site in a virtual directory.

There's nothing evil about having paths specified from the web root. This is pretty much how the site will eventually be deployed.

The approach you've taken means that code will need to execute every time you want to resolve a URL. This is really something that should be happening for free, and it can.

If you're using Visual Studio's built-in web server for development, you can easily have a site that is defined at the web root.

If not, and you're on XP, consider using IISAdmin.NET. This tool allows you to set up multiple websites on your local copy of IIS and switch between them as the need arises.

http://iisadmin.codeplex.com/

Paul Alan Taylor
+1  A: 

If it's feasible you could just make the it a web site proper in IIS and just assign it a different port.

I take this approach on my dev machine if I want to get a website working on IIS proper rather than Cassini. So everything will be under http://localhost:[portnumber]/.

If you have to use a virtual directory I'm out of ideas.

Castrohenge