Steve - DND wrote:
We're currently working on a project with v1.0 of the .Net Framework, and
are experiencing some issues with System.Uri. We have two Uri objects:
Uri uriBase = new Uri("http://localhost/VirtualDirectory/");
Uri uriDestination = new
Uri("http://localhost/VirtualDirectory/SomeFile.aspx");
When we do uriBase.MakeRelative(uriDestination) on one machine we end up
with "SomeFile.aspx", and on another machine we end up with
"../VirtualDirectory/SomeFile.aspx". Both of these are technically correct,
but it's been quite irritating since we now have to write code to deal with
both instances. Any thoughts on what is going on here? Is there some setting
somewhere to indicate how relative URLs are handled?
Are you sure that there's not a space, null, or some other easy
-to-overlook character embedded in the base URI on the machine that
you're seeing strange results on? You might get that unwittingly if
you're building up the uriBase by concatenating various bits from
configuration file or user input, for example.
Look at what happens if there's a space in the baseUri:
================================================== =========
static void Main(string[] args) {
Uri uriBase = new Uri("http://localhost/VirtualDirectory/");
Uri uriBase2 = new Uri("http://localhost/VirtualDirectory /");
Console.WriteLine( "uriBase = \"{0}\"", uriBase.AbsoluteUri);
Console.WriteLine( "uriBase2 = \"{0}\"", uriBase2.AbsoluteUri);
Console.WriteLine( "uriBase2 = \"{0}\"", uriBase2.ToString());
Uri uriDestination = new
Uri("http://localhost/VirtualDirectory/SomeFile.aspx");
Console.WriteLine( "URL relative to uriBase: \"{0}\"",
uriBase.MakeRelative(uriDestination));
Console.WriteLine( "URL relative to uriBase2: \"{0}\"",
uriBase2.MakeRelative(uriDestination));
}
================================================== =========
The results look similar to what you're getting:
uriBase = "http://localhost/VirtualDirectory/"
uriBase2 = "http://localhost/VirtualDirectory%20/"
uriBase2 = "http://localhost/VirtualDirectory /"
URL relative to uriBase: "SomeFile.aspx"
URL relative to uriBase2: "../VirtualDirectory/SomeFile.aspx"
--
mikeb