Last active
May 15, 2019 13:04
Example Uri properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Uri pageUri = new Uri("https://www.example.com/folder/page.aspx?query=1&sample=2#anchor"); | |
Uri simpleUri = new Uri("http://www.example.com/folder"); | |
Console.WriteLine("Uri Properties:"); | |
Console.WriteLine(); | |
foreach (Uri uri in new[] { pageUri, simpleUri }) | |
{ | |
Console.WriteLine("Using : {0}", uri); | |
Console.WriteLine("AbsolutePath : {0}", uri.AbsolutePath); | |
Console.WriteLine("AbsoluteUri : {0}", uri.AbsoluteUri); | |
Console.WriteLine("Authority : {0}", uri.Authority); | |
Console.WriteLine("DnsSafeHost : {0}", uri.DnsSafeHost); | |
Console.WriteLine("Fragment : {0}", uri.Fragment); | |
Console.WriteLine("Host : {0}", uri.Host); | |
Console.WriteLine("HostNameType : {0}", uri.HostNameType); | |
Console.WriteLine("IsAbsoluteUri : {0}", uri.IsAbsoluteUri); | |
Console.WriteLine("IsDefaultPort : {0}", uri.IsDefaultPort); | |
Console.WriteLine("IsFile : {0}", uri.IsFile); | |
Console.WriteLine("IsLoopback : {0}", uri.IsLoopback); | |
Console.WriteLine("IsUnc : {0}", uri.IsUnc); | |
Console.WriteLine("LocalPath : {0}", uri.LocalPath); | |
Console.WriteLine("OriginalString : {0}", uri.OriginalString); | |
Console.WriteLine("PathAndQuery : {0}", uri.PathAndQuery); | |
Console.WriteLine("Port : {0}", uri.Port); | |
Console.WriteLine("Query : {0}", uri.Query); | |
Console.WriteLine("Scheme : {0}", uri.Scheme); | |
Console.WriteLine("Segments : {0}", string.Join(", ", uri.Segments)); | |
Console.WriteLine("UserEscaped : {0}", uri.UserEscaped); | |
Console.WriteLine("UserInfo : {0}", uri.UserInfo); | |
Console.WriteLine(); | |
} | |
Console.WriteLine("Uri.GetLeftPart(UriPartial part)"); | |
Console.WriteLine(); | |
foreach (Uri uri in new[] { pageUri, simpleUri }) | |
{ | |
Console.WriteLine("Using : {0}", uri); | |
Console.WriteLine("UriPartial.Authority : {0}", uri.GetLeftPart(UriPartial.Authority)); | |
Console.WriteLine("UriPartial.Path : {0}", uri.GetLeftPart(UriPartial.Path)); | |
Console.WriteLine("UriPartial.Query : {0}", uri.GetLeftPart(UriPartial.Query)); | |
Console.WriteLine("UriPartial.Scheme : {0}", uri.GetLeftPart(UriPartial.Scheme)); | |
Console.WriteLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment