Uri.MakeRelativeUri(Uri) Método

Definição

Determina a diferença entre duas Uri instâncias.

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

Parâmetros

uri
Uri

O URI para comparar com o URI atual.

Devoluções

Uri

Se o nome do host e o esquema desta instância de URI e uri forem iguais, então este método devolve um relativo Uri que, quando anexado à instância atual do URI, produz uri.

Se o nome do anfitrião ou esquema for diferente, então este método devolve a Uri que representa o uri parâmetro.

Exceções

uri é null.

Esta instância representa um URI relativo, e esta propriedade é válida apenas para URIs absolutos.

Exemplos

O exemplo seguinte cria 2 Uri instâncias. A diferença na informação do caminho é escrita para a consola.

// 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

Observações

A tabela seguinte mostra a instância de URI, toUri, e os resultados de chamar MakeRelativeUri.

Instância atual do URI toUri Valor de retorno
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

A informação do utilizador, se presente no URI, é ignorada.

Aplica-se a