RobD
RobD

Reputation: 1704

Simple way to change whole project to root relative paths

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.

Upvotes: 0

Views: 295

Answers (3)

Jay
Jay

Reputation: 27492

I guess a key question is how big this app is.

There aren't all that many different places to put a url. Why not search for

="/

and

='/

That is, an equal sign, a double or single quote, and a slash. That should turn up most of the places that assign a URL. Then you'd see all the places where you're setting such things, like src= and navigateurl= and whatever.

It would be a pain. I'm not saying you'd get it done in ten minutes. If this is something that you need to get done today and it's a big app, I wouldn't take it on. But if it's something you're going to be working on making changes to and testing for a week, I think you could make a first cut at cleaning up the the URL's and then see what shakes out in testing.

Upvotes: 0

Castrohenge
Castrohenge

Reputation: 8993

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.

Upvotes: 1

Paul Alan Taylor
Paul Alan Taylor

Reputation: 10680

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/

Upvotes: 2

Related Questions