Uri.MakeRelativeUri(Uri) Metoda

Definice

Určuje rozdíl mezi dvěma Uri instancemi.

public:
 Uri ^ MakeRelativeUri(Uri ^ uri);
public Uri MakeRelativeUri(Uri uri);
member this.MakeRelativeUri : Uri -> Uri
Public Function MakeRelativeUri (uri As Uri) As Uri

Parametry

uri
Uri

Identifikátor URI pro porovnání s aktuálním identifikátorem URI.

Návraty

Uri

Pokud název hostitele a schéma této instance identifikátoru URI a uri jsou stejné, vrátí tato metoda relativní Uri hodnotu, která při připojení k aktuální instanci identifikátoru URI vrátí uri.

Pokud se název hostitele nebo schéma liší, vrátí tato metoda Uri hodnotu, která představuje uri parametr.

Výjimky

uri je null.

Tato instance představuje relativní identifikátor URI a tato vlastnost je platná pouze pro absolutní identifikátory URI.

Příklady

Následující příklad vytvoří 2 Uri instance. Rozdíl v informacích o cestě se zapíše do konzoly.

// Create a base Uri.
Uri address1 = new Uri("http://www.contoso.com/");

// Create a new Uri from a string.
Uri address2 = new Uri("http://www.contoso.com/index.htm?date=today");

// Determine the relative Uri.
Console.WriteLine("The difference is {0}", address1.MakeRelativeUri(address2));
// Create a base Uri.
let address1 = Uri "http://www.contoso.com/"

// Create a new Uri from a string.
let address2 = Uri "http://www.contoso.com/index.htm?date=today"

// Determine the relative Uri.
printfn $"The difference is {address1.MakeRelativeUri address2}"
    ' Create a base Uri.
    Dim address1 As New Uri("http://www.contoso.com/")
    
    ' Create a new Uri from a string.
    Dim address2 As New Uri("http://www.contoso.com/index.htm?date=today")
    
    ' Determine the relative Uri.  
    Console.WriteLine("The difference is {0}", address1.MakeRelativeUri(address2))

End Sub

Poznámky

Následující tabulka ukazuje instanci toUriidentifikátoru URI a výsledky volání MakeRelativeUri.

Aktuální instance identifikátoru URI toUri Návratová hodnota
http://www.contoso.com/ http://www.contoso.com/test/test.htm test/test.htm
http://www.contoso.com/test1/ http://www.contoso.com/ ../
http://www.contoso.com:8000/ http://www.contoso.com/test/test.htm http://www.contoso.com/test/test.htm
http://username@www.contoso.com/ http://www.contoso.com/test1/test1.txt test1/test1.txt

Informace o uživateli, pokud jsou přítomné v identifikátoru URI, se ignorují.

Platí pro