views:

264

answers:

1
Dim x AS New URI("http://www.example.com/test//test.asp")
Dim rel AS New URI("http://www.example.com/xxx/xxx.asp")
Console.Writeline(x.MakeRelativeUri(rel).Tostring())

In here output is:

../../xxx/xxx.asp

Which looks correct almost all web servers will process the two of the following as same request:

http://www.example.com/test//test.asp
http://www.example.com/test/test.asp

What's the best way to fix this behaviour is there any API to do this, or shall manually create a new URI and remove all // in the path?

A: 

First off, your code is not C# but VB, so tags are wrong.

Can you use this code instead, which gives the "correct" url since the // are in the baseuri and will be discarded?

var x2 = new Uri(x, rel);

Or is it important to get the ../ backtracking in the url?

The MakeRelativeUri function does correct according to the RFC, but it fails according to normal convention. I would suggest you normalize the url yourself, or use my example above if possible.

x = new Uri(Regex.Replace(x.OriginalString, "[^:]//", "/"));
Mikael Svenson