System.Uri.IsLoopback Property

Gets whether the specified Uri references the local host.

Syntax

public bool IsLoopback { get; }

Value

true if the host of the current instance is the reserved hostname "localhost" or the loop-back IP address (127.0.0.1); otherwise, false.

Remarks

Uri.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). All other URIs return false.

Example

The following example demonstrates the Uri.IsLoopback property.

C# Example

using System;

public class UriTest {
 public static void Main() {
 Uri myUri = new Uri("http://127.0.0.1/index.htm", true);
 Console.WriteLine("{0} is loopback? {1}", myUri.ToString(), myUri.IsLoopback);

 myUri = new Uri("http://localhost/index.htm", true);
 Console.WriteLine("{0} is loopback? {1}", myUri.ToString(), myUri.IsLoopback);

 }
}

The output is

http://127.0.0.1/index.htm is loopback? True

http://localhost/index.htm is loopback? True

Requirements

Namespace: System
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0