Gets whether the specified Uri references the local host.
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.
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.
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