URl rewrite and relative paths

P

Paul Hatcher

Sorry to post this again - I didn't use my MSDN alias previously...

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 for example.

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
 
S

Steven Cheng[MSFT]

Hi Paul,

Welcome to ASPNET newsgroup.
As for the problem you mentioned, I've also reproduced it on my side. Seems
there is something wrong with the Control when Render the certain Html Tag.
I'll consult some other experts on this to see whehter this issue is
already addressed and will let you know as soon as I get any update.

Thank you for your understanding.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
V

vMike

Paul Hatcher said:
Sorry to post this again - I didn't use my MSDN alias previously...

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.
Instead of using http://www.mysite.com/links/1023.apx could you use
something like http://www.mysite.com/1023.apx (or even better is
http://www.mysite.com/link-1023.aspx b/c it be easier to detect and more SEO
friendly) and have that rewrite to
http://www.mysite.com/links.aspx?link=1023. Just a thought.

Mike
 
P

Paul Hatcher

Welcome to ASPNET newsgroup.
I've been around since Beta2 of .NET 1.0, but been a bit quiet :)

Thanks for the response.

Paul
 
S

Steven Cheng[MSFT]

Paul,

I've contacted the certain dev tester on this function and send them the
repro code, they're currently investigating on it. I'll update you as soon
as I got any feedback from them. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Paul,

As got from our DEV Tester, the problem is raised in the
Context.RewritePath method, so we're currently contacting the dev test of
that function to see whether they've any action plan on this. I just post
this message to let you know we're still keeping focus on this. Thanks for
your understanding.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi Paul,

Sorry for keep you waiting. After some further contacting with our dev/test
guys, they've addressed this problem as a known limitation of the current
ASP.NET(1.x).

In Whidbey, we introduced 2 new API to work around this problem:
public void RewritePath(String path, bool rebaseClientPath);
public void RewritePath(String filePath, String pathInfo, String
queryString, bool setClientFilePath);

So currently, we may need to manually call Control.ResolveUrl to corrently
parse the relative path. Sorry for the inconvenience it brings you.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Can you give me an example of how you would do this in practice, i.e. does
this mean I need to create derived controls so that I can correctly override
the behaviour?

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,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top