Share via


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.

Inheritance Hierarchy

System. . :: . .Object
  System..::..Uri

Namespace:  System
Assembly:  System.Http (in System.Http.dll)

Syntax

'Declaration
Public Class Uri
public class Uri
public ref class Uri
type Uri =  class end
public class Uri

The Uri type exposes the following members.

Constructors

  Name Description
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.

Top

Properties

  Name Description
Public property AbsolutePath Gets the absolute path of the URI.
Public property AbsoluteUri Gets the absolute URI.
Public property Host Gets the host component of this instance.
Public property HostNameType Gets the type of the host name specified in the URI.
Public property IsAbsoluteUri Gets whether the Uri instance is absolute.
Public property IsLoopback Gets whether the specified Uri references the local host.
Public property IsUnc Gets whether the specified Uri is a universal naming convention (UNC) path.
Public property OriginalString Gets the original URI string that was passed to the Uri constructor.
Public property Port Gets the port number of this URI.
Public property Scheme Gets the scheme name for this URI.

Top

Methods

  Name Description
Protected method ConstructAbsoluteUri Constructs an absolute Uri from a URI string.
Public method Equals Compares two Uri instances for equality. (Overrides Object. . :: . .Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Gets the hash code for the URI. (Overrides Object. . :: . .GetHashCode() () () ().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method IsAlpha Determines whehter the character value is an alpha character.
Protected method IsAlphaNumeric Determines whether the character is an alpha or numeric.
Protected method IsHex Determines whether the value is hexadecimal.
Protected method IsIPv4 Determines whether the host name is an IP address 4 bytes, such as 192.1.1.1.
Public methodStatic member IsWellFormedUriString Indicates 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 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method ParseUriString Parses a URI string into Uri variables.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Protected method ValidateRelativePath Parses relative Uri into variables.
Protected method ValidateUriPart Validates that part of Uri after scheme is valid for an unknown Uri scheme.
Protected method ValidateUrn Parses urn string into Uri variables.

Top

Operators

  Name Description
Public operatorStatic member Equality Determines whether two Uri instances have the same value.
Public operatorStatic member Inequality Determines whether two Uri instances do not have the same value.

Top

Fields

  Name Description
Public fieldStatic member HttpDefaultPort Contains the default port for http protocol. The value is set to 80.
Public fieldStatic member HttpsDefaultPort Contains the default port for https protocol. The value is set to 443.
Protected field m_AbsolutePath Contains the absolute path of the URI.
Protected field m_Flags Contains the internal flags.
Protected field m_host Contains ttthe host name (http and https).
Protected field m_hostNameType Contains the type of the host.
Protected field m_isAbsoluteUri Contains the absolute URI.
Protected field m_isUnc Contains a value that indicates whether the specified Uri is a universal naming convention (UNC) path.
Protected field m_OriginalUriString Contains the original URI string that was passed to the Uri constructor.
Protected field m_port Contains the port number of this URI.
Protected field m_scheme Contains the scheme name for this URI.
Protected fieldStatic member UnknownPort Contains a value used to indicate the port for this protocol is unknown.

Top

Remarks

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.

Thread Safety

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

See Also

Reference

System Namespace