Url Rewrite and relative paths

P

Paul Hatcher

I'm using a url rewriting mechanism to make my site's urls more
search-engine/user-friendly, so we have http://www.mysite.com/links/1023.apx
which is actually internally mapped to
http://www.mysite.com/links.aspx?link=1023. This works fine and makes the
site look a lot cleaner.

The problem I'm having is with controls on the target page. I render all the
urls as root relative so that I'm independent of whether I'm a root web or
an application, so we have ~/images/img1.jpg for images and and
~/links/4096.aspx as a child link of 1023. The problem is that the ASP.NET
controls convert my relative paths to images/img1.jpg and links/4096.aspx,
when evaluated these become http://www.mysite.com/links/images/img1.jpg and
http://www.mysite.com/links/links/4096.aspx which of course don't exist.

Now interestingly, if I call ResolveUrl in the page on say ~/images/img1.jpg
I correctly get /images/img1.jpg, there's basically a different behaviour
between ResolveUrl and Control.ResolveUrl. I have a workaround, which is to
make everything an absolute path, but it's not very satisfactory since it
makes demoing stuff to clients a pain - you have to have a root web
available rather than just creating an application directory somewhere.

I'd call this a bug, since there should only be one implementation of
something like ResolveUrl.

Anyone else found this and have a better workaround?

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top