Uri.IsLoopback 属性
定义
public:
property bool IsLoopback { bool get(); };
public bool IsLoopback { get; }
member this.IsLoopback : bool
Public ReadOnly Property IsLoopback As Boolean
属性值
true 如果此 Uri 引用了本地主机,则为; 否则为 false 。true if this Uri references the local host; otherwise, false.
例外
此实例代表一个相对 URI,而此属性仅对绝对 URI 有效。This instance represents a relative URI, and this property is valid only for absolute URIs.
示例
下面的示例创建一个 Uri 实例,并确定它是否引用了本地主机。The following example creates a Uri instance and determines whether it references a local host.
Uri^ uriAddress2 = gcnew Uri( "file://server/filename.ext" );
Console::WriteLine( uriAddress2->LocalPath );
Console::WriteLine( "Uri {0} a UNC path", uriAddress2->IsUnc ? (String^)"is" : "is not" );
Console::WriteLine( "Uri {0} a local host", uriAddress2->IsLoopback ? (String^)"is" : "is not" );
Console::WriteLine( "Uri {0} a file", uriAddress2->IsFile ? (String^)"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
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
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
注解
IsLoopbacktrue如果创建此实例时指定的 uri 是127.0.0.1、环回或 localhost,或者 uri 未指定主机信息 (例如,file:///c:Dir/file.txt) ,则返回。IsLoopback returns true if the URI specified when this instance was created was 127.0.0.1, loopback, or localhost, or if the URI did not specify host information (for example, file:///c:Dir/file.txt). 所有其他 Uri 返回 false 。All other URIs return false.