Skip to main content
 Collapse AllExpand All      Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: F# Code: JScript 
Uri Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.

Namespace:   System
Assembly:  System.Http (in System.Http.dll)
Public Class Uri
public class Uri
public ref class Uri
type Uri =  class end
public class Uri

The Uri type exposes the following members.

Public method Uri(String)Initializes a new instance of the Uri class with the specified URI.
Public method Uri(String, UriKind)Initializes a new instance of the Uri class with the specified URI. This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate.
Public property AbsolutePathGets the absolute path of the URI.
Public property AbsoluteUriGets the absolute URI.
Public property HostGets the host component of this instance.
Public property HostNameTypeGets the type of the host name specified in the URI.
Public property IsAbsoluteUriGets whether the Uri instance is absolute.
Public property IsLoopbackGets whether the specified Uri references the local host.
Public property IsUncGets whether the specified Uri is a universal naming convention (UNC) path.
Public property OriginalStringGets the original URI string that was passed to the Uri constructor.
Public property PortGets the port number of this URI.
Public property SchemeGets the scheme name for this URI.
Protected method ConstructAbsoluteUriConstructs an absolute Uri from a URI string.
Public method EqualsCompares two Uri instances for equality. (Overrides Object..::..Equals(Object).)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCodeGets the hash code for the URI. (Overrides Object..::..GetHashCode()()()().)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method IsAlphaDetermines whehter the character value is an alpha character.
Protected method IsAlphaNumericDetermines whether the character is an alpha or numeric.
Protected method IsHexDetermines whether the value is hexadecimal.
Protected method IsIPv4Determines whether the host name is an IP address 4 bytes, such as
Public method Static member IsWellFormedUriStringIndicates whether the string is well-formed by attempting to construct a URI with the string and ensures that the string does not require further escaping.
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected method ParseUriStringParses a URI string into Uri variables.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Protected method ValidateRelativePathParses relative Uri into variables.
Protected method ValidateUriPartValidates that part of Uri after scheme is valid for an unknown Uri scheme.
Protected method ValidateUrnParses urn string into Uri variables.
Public operator Static member EqualityDetermines whether two Uri instances have the same value.
Public operator Static member InequalityDetermines whether two Uri instances do not have the same value.
Public field Static member HttpDefaultPortContains the default port for http protocol. The value is set to 80.
Public field Static member HttpsDefaultPortContains the default port for https protocol. The value is set to 443.
Protected field m_AbsolutePathContains the absolute path of the URI.
Protected field m_FlagsContains the internal flags.
Protected field m_hostContains ttthe host name (http and https).
Protected field m_hostNameTypeContains the type of the host.
Protected field m_isAbsoluteUriContains the absolute URI.
Protected field m_isUncContains a value that indicates whether the specified Uri is a universal naming convention (UNC) path.
Protected field m_OriginalUriStringContains the original URI string that was passed to the Uri constructor.
Protected field m_portContains the port number of this URI.
Protected field m_schemeContains the scheme name for this URI.
Protected field Static member UnknownPortContains a value used to indicate the port for this protocol is unknown.

A URI is a compact representation of a resource available to your application on the intranet or Internet. The Uri class defines the properties and methods for handling URIs, including parsing, comparing, and combining.

The Uri constructors do not escape URI strings if the string is a well-formed URI including a scheme identifier.

The Uri properties return a canonical data representation in escaped encoding, with all characters with Unicode values greater than 127 replaced with their hexadecimal equivalents. To put the URI in canonical form, the Uri constructor performs the following steps:

  • Converts the URI scheme to lowercase.

  • Converts the host name to lowercase.

  • If the host name is an IPv6 address, the canonical IPv6 address is used. ScopeId and other optional IPv6 data are removed.

  • Removes default and empty port numbers.

  • Canonicalizes the path for hierarchical URIs by compacting sequences such as /./, /../, //, including escaped representations. Note that there are some schemes for which escaped representations are not compacted.

  • For hierarchical URIs, if the host is not terminated with a forward slash (/), one is added.

  • By default, any reserved characters in the URI are escaped in accordance with RFC 2396. This behavior changes if International Resource Identifiers or International Domain Name parsing is enabled in which case reserved characters in the URI are escaped in accordance with RFC 3986 and RFC 3987.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.