Uri.IsBaseOf(Uri) Uri.IsBaseOf(Uri) Uri.IsBaseOf(Uri) Method

定义

确定当前的 Uri 实例是否为指定 Uri 实例的基。Determines whether the current Uri instance is a base of the specified Uri instance.

public:
 bool IsBaseOf(Uri ^ uri);
public bool IsBaseOf (Uri uri);
member this.IsBaseOf : Uri -> bool

参数

uri
Uri Uri Uri

要测试的指定 Uri 实例。The specified Uri instance to test.

返回

如果当前 true 实例是 Uri 的基,则为 uri;否则,为 falsetrue if the current Uri instance is a base of uri; otherwise, false.

异常

示例

此示例将创建Uri实例,它表示基础Uri实例。This example creates a Uri instance that represents a base Uri instance. 然后,创建第二个Uri从字符串的实例。It then creates a second Uri instance from a string. 它将调用IsBaseOf以确定基本实例是否为第二个实例的基。It calls IsBaseOf to determine whether the base instance is the base of the second instance. 结果将写入控制台。The outcome is written to the console.

// Create a base Uri.
Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );

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

// Determine whether BaseUri is a base of UriAddress.  
if ( baseUri->IsBaseOf( uriAddress ) )
   Console::WriteLine( "{0} is the base of {1}", baseUri, uriAddress );
// Create a base Uri.
Uri baseUri = new Uri("http://www.contoso.com/");

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

// Determine whether BaseUri is a base of UriAddress.  
if (baseUri.IsBaseOf(uriAddress))
    Console.WriteLine("{0} is the base of {1}", baseUri, uriAddress);
' Create a base Uri.
Dim baseUri As New Uri("http://www.contoso.com/")

' Create a new Uri from a string.
Dim uriAddress As New Uri("http://www.contoso.com/index.htm?date=today")

' Determine whether BaseUri is a base of UriAddress.  
If baseUri.IsBaseOf(uriAddress) Then
    Console.WriteLine("{0} is the base of {1}", baseUri, uriAddress)
End If

注解

IsBaseOf 用于比较当前Uri实例与指定Uri来确定此 URI 是否为指定的基础UriIsBaseOf is used to compare the current Uri instance to a specified Uri to determine whether this URI is a base for the specified Uri. 当比较两个Uri对象,以确定基本关系,用户信息 (UserInfo) 则不会评估。When comparing two Uri objects to determine a base relationship, the user information (UserInfo) is not evaluated. 在比较两个 Uri (uri1 和 uri2) 时,如果当你忽略 uri2 中的所有内容后的最后一个斜杠 (/),两个 Uri 同时 uri1 就是 uri2 的基。When comparing two URIs (uri1 and uri2), uri1 is the base of uri2 if, when you ignore everything in uri2 after the last slash (/), the two URIs are identical. 使用http://host/path/path/file?query作为基 URI,下表显示了,无论它是其他 Uri 的基础。Using http://host/path/path/file?query as the base URI, the following table shows whether it is a base for other URIs.

URIURI http://host/path/path/file?query 是基项http://host/path/path/file?query is base of
http://host/path/path/file/ yes
http://host/path/path/#fragment yes
http://host/path/path/MoreDir/"http://host/path/path/MoreDir/" yes
http://host/path/path/OtherFile?Query yes
http://host/path/path/ yes
http://host/path/path/file yes
http://host/path/path no
http://host/path/path?query no
http://host/path/path#Fragment no
http://host/path/path2/ no
://host/path/path2/MoreDir://host/path/path2/MoreDir no
http://host/path/File no

适用于