473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Uri.MakeRelative() Different Results

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?

Thanks,
Steve
Nov 15 '05 #1
4 3417
Anyone have any thoughts on this?

"Steve - DND" <ng@digitalnothing.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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?

Thanks,
Steve

Nov 15 '05 #2
Even looking at the IL for the method it is strange why it does this. Are
you sure the same version of .NET is on both machines? You haven't applied
service packs to only one of the machines and you haven't accidentally
upgraded to V1.1?
--
Justin Rogers
DigiTec Web Consultants, LLC.

"Steve - DND" <ng@digitalnothing.com> wrote in message
news:Op**************@TK2MSFTNGP10.phx.gbl...
Anyone have any thoughts on this?

"Steve - DND" <ng@digitalnothing.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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?

Thanks,
Steve


Nov 15 '05 #3
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
Nov 15 '05 #4
> 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.


I figured this out today. It turns out that I was living in my
case-insensitive Windows world, and was expecting the URI's to be treated as
such. The reason this was occurring was that my favorite to the development
site was saved with the proper casing, whereas the other developer's
favorite was saved with improper case. After I found this out it completely
made sense, since in a case-sensitive environment ala UNIX or Linux,
http://somedomain.com/VIRTUALDIRECTORY and
http://somedomain.com/VirtualDirectory are two very different locations.
After taking the Uri, and converting it to lowercase, and doing the same
with the comparison Uri everything worked as expected.

Thanks,
Steve
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave | last post by:
I'm getting different results when I display a value in the Output window as opposed to the Immediate window. Why? Code to recreate problem: 'Purpose: Get different results from Output...
3
by: Tao.Young | last post by:
Hi, I met with a very strange problem: the same function will generate different results, but when i uncomment Line1, it'll get the same results. anyone can tell me why? the code is...
1
by: RM | last post by:
I am using DataSet's .ReadXml() method to parse an XML file that has an inline schema and Im getting "different" results on various machines using the same myDataSet.ReadXml("myExample.xml"). ...
0
by: Nathan Sokalski | last post by:
When using the MakeRelative() method of the Uri class, I have noticed that the Query and Fragment are never returned. I ran the following code and recieved the following results: Dim initialUri1...
22
by: silversurfer2025 | last post by:
Hello everybdy, I am a little confused for the following reason: In my code I used a simple for-loop in order to initialize a 2D-array of floats to zero. Because of efficiency reasons, I changed...
2
by: jonathan184 | last post by:
Hi I am having a problme where the results of the sql count is not matching the results of the perl script sql count. The script was working fine up till Wed last week and after that the results...
12
by: colin | last post by:
Hi, Ive got a difference in results depending on wether I run my app in the debugger, or run it seperatly (or with <ctrl-f5>) the results in the debugger seem to be more correct, although the...
6
by: Avi | last post by:
I need to implement the following calculation: f = (a*b) + (c*d) where a,b,c,d are given double values and f is a double variable for the result I found out that using two different...
1
by: blondieUA | last post by:
Hello guys! I have some problem with creating the result page :( I need to create a web-page for my college course in Computer Science. I decided to create a site about Horoscopes. So if a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.