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

The Uri type exposes the following members.

Public methodUri(String)Initializes a new instance of the Uri class with the specified URI.
Public methodUri(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 propertyAbsolutePathGets the absolute path of the URI.
Public propertyAbsoluteUriGets the absolute URI.
Public propertyHostGets the host component of this instance.
Public propertyHostNameTypeGets the type of the host name specified in the URI.
Public propertyIsAbsoluteUriGets whether the Uri instance is absolute.
Public propertyIsLoopbackGets whether the specified Uri references the local host.
Public propertyIsUncGets whether the specified Uri is a universal naming convention (UNC) path.
Public propertyOriginalStringGets the original URI string that was passed to the Uri constructor.
Public propertyPortGets the port number of this URI.
Public propertySchemeGets the scheme name for this URI.

Protected methodConstructAbsoluteUriConstructs an absolute Uri from a URI string.
Public methodEqualsCompares two Uri instances for equality. (Overrides Object..::..Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeGets the hash code for the URI. (Overrides Object..::..GetHashCode()()()().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodIsAlphaDetermines whehter the character value is an alpha character.
Protected methodIsAlphaNumericDetermines whether the character is an alpha or numeric.
Protected methodIsHexDetermines whether the value is hexadecimal.
Protected methodIsIPv4Determines whether the host name is an IP address 4 bytes, such as
Public methodStatic memberIsWellFormedUriStringIndicates 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 methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodParseUriStringParses a URI string into Uri variables.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Protected methodValidateRelativePathParses relative Uri into variables.
Protected methodValidateUriPartValidates that part of Uri after scheme is valid for an unknown Uri scheme.
Protected methodValidateUrnParses urn string into Uri variables.

Public operatorStatic memberEqualityDetermines whether two Uri instances have the same value.
Public operatorStatic memberInequalityDetermines whether two Uri instances do not have the same value.

Public fieldStatic memberHttpDefaultPortContains the default port for http protocol. The value is set to 80.
Public fieldStatic memberHttpsDefaultPortContains the default port for https protocol. The value is set to 443.
Protected fieldm_AbsolutePathContains the absolute path of the URI.
Protected fieldm_FlagsContains the internal flags.
Protected fieldm_hostContains ttthe host name (http and https).
Protected fieldm_hostNameTypeContains the type of the host.
Protected fieldm_isAbsoluteUriContains the absolute URI.
Protected fieldm_isUncContains a value that indicates whether the specified Uri is a universal naming convention (UNC) path.
Protected fieldm_OriginalUriStringContains the original URI string that was passed to the Uri constructor.
Protected fieldm_portContains the port number of this URI.
Protected fieldm_schemeContains the scheme name for this URI.
Protected fieldStatic memberUnknownPortContains 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.