語言

Uri.IsBaseOf(Uri) 方法

定義

判斷目前 Uri 實例是否為指定 Uri 實例的基底。

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

參數

uri
Uri

要測試指定的 URI。

傳回

true 若當前 Uri 實例是 的 uri基底;否則, false。

例外狀況

uri 是 null。

範例

此範例 Uri 建立一個代表基底 Uri 實例的實例。 接著它會從一個字串建立第二個 Uri 實例。 它呼叫 IsBaseOf 來判斷基底實例是否為第二個實例的基底。 結果會寫入主控台。

// 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.
let baseUri = Uri "http://www.contoso.com/"

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

// Determine whether BaseUri is a base of UriAddress.
if baseUri.IsBaseOf uriAddress then
    printfn $"{baseUri} is the base of {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 是否為指定 Uri的基底。 在比較兩個 Uri 物件以確定基礎關係時,使用者資訊(UserInfo)不會被評估。 比較兩個 URI(uri1 和 uri2)時,如果忽略 uri1 和 uri2 中所有東西,且 uri2 剛好以 uri1 開頭,則 uri1 是 uri2 的基底。 以下 http://host/path/path/file?query 表格以 URI 為基礎,顯示它是否是其他 URI 的基礎。

URI http://host/path/path/file?query 是 的基底
http://host/path/path/file/ 是
http://host/path/path/#fragment 是
http://host/path/path/MoreDir/" 是
http://host/path/path/OtherFile?Query 是
http://host/path/path/ 是
http://host/path/path/file 是
http://host/path/path 否
http://host/path/path?query 否
http://host/path/path#Fragment 否
http://host/path/path2/ 否
://host/path/path2/MoreDir 否
http://host/path/File 否

適用於