tags:

views:

36

answers:

1

Lets say I have a web site hosted on a computer named "linux" and it is part of two different networks with the addresses 192.168.1.1 and 10.1.1.1. When working locally on "linux", I can access this web site through the following URLs :

http://192.168.1.1/ http://10.1.1.1/ http://linux/ http://localhost/ http://127.0.0.1/

Working on another machine on the network "10.1.1.0/24" I can use the following :

http://10.1.1.1/ http://linux/

But on "192.168.1.0/24" I can only use :

http://192.168.1.1/ http://linux/

I'm developing an application that compares URLs, and on this application's context two URLs are equal if they point to the same resource.

Is there a quick way of doing that kind of comparison using the URI class in C# ?

+3  A: 

There's no way the URI class will help you; it can only determine if two URIs are the same URI, and they're only the same URI if they have the same server name / IP address.

The best option is to download the resource from both URLs and see if it is the same resource by checking for equality and assuming that two resources are the same resource if they're the same sequence of bits.

That isn't an option for me, the perfomance cost could be too great. I was hoping for something that could match the 'host address' part of the URI's, then all that was left to compare would be the relative path and port... – Thiado de Arruda

Unfortunately, there is nothing in the framework that will do what you want out of the box, because there's no reliable way of mapping different host names to the same host and therefore the same resource.

You are going to have to have some sort of mapping of hosts to the various aliases of those hosts and query for them yourself. The URI.Host property will get the host name of the URI in question for you, but you'll have to translate it yourself. Nothing in the framework is going to be able to do it for you.

Randolpho
That isn't an option for me, the perfomance cost could be too great. I was hoping for something that could match the 'host address' part of the URI's, then all that was left to compare would be the relative path and port...
Thiado de Arruda
@Thiado de Arruda: I replied as an edit to my answer.
Randolpho