語言

Uri.IsLoopback 屬性

定義

會取得一個值,表示指定的 Uri 是否參考本地主機。

public:
 property bool IsLoopback { bool get(); };
public bool IsLoopback { get; }
member this.IsLoopback : bool
Public ReadOnly Property IsLoopback As Boolean

屬性值

true若此參考Uri本地主機;否則,。 false

例外狀況

此實例代表一個相對 URI,且此性質僅適用於絕對 URI。

範例

以下範例建立一個 Uri 實例,並判斷其是否參考本地主機。

Uri uriAddress2 =  new Uri("file://server/filename.ext");
Console.WriteLine(uriAddress2.LocalPath);
Console.WriteLine("Uri {0} a UNC path", uriAddress2.IsUnc ? "is" : "is not");
Console.WriteLine("Uri {0} a local host", uriAddress2.IsLoopback ? "is" : "is not");
Console.WriteLine("Uri {0} a file", uriAddress2.IsFile ? "is" : "is not");
// The example displays the following output:
//    \\server\filename.ext
//    Uri is a UNC path
//    Uri is not a local host
//    Uri is a file
let uriAddress2 = Uri "file://server/filename.ext"
printfn $"{uriAddress2.LocalPath}"
printfn $"""Uri {if uriAddress2.IsUnc then "is" else "is not"} a UNC path"""
printfn $"""Uri {if uriAddress2.IsLoopback then "is" else "is not"} a local host"""
printfn $"""Uri {if uriAddress2.IsFile then "is" else "is not"} a file"""
// The example displays the following output:
//    \\server\filename.ext
//    Uri is a UNC path
//    Uri is not a local host
//    Uri is a file
Dim uriAddress2 As New Uri("file://server/filename.ext")
Console.WriteLine(uriAddress2.LocalPath)
Console.WriteLine("Uri {0} a UNC path", IIf(uriAddress2.IsUnc, "is", "is not")) 'TODO: For performance reasons this should be changed to nested IF statements
Console.WriteLine("Uri {0} a local host", IIf(uriAddress2.IsLoopback, "is", "is not")) 'TODO: For performance reasons this should be changed to nested IF statements
Console.WriteLine("Uri {0} a file", IIf(uriAddress2.IsFile, "is", "is not")) 'TODO: For performance reasons this should be changed to nested IF statements
' The example displays the following output:
'    \\server\filename.ext
'    Uri is a UNC path
'    Uri is not a local host
'    Uri is a file

備註

IsLoopback true如果 URI 指定此實例建立時間為 127.0.0.1、迴圈或 localhost,或未指定主機資訊(例如 file:///c:Dir/file.txt)。 其他所有 URI 都會返回 false。

適用於