Show / Hide Table of Contents

    Class Uri

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

    Inheritance
    Object
    Uri
    Inherited Members
    Object.ToString()
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: System
    Assembly: System.Net.Http.dll
    Syntax
    public class Uri

    Constructors

    | Improve this Doc View Source

    Uri(String)

    Initializes a new instance of the Uri class with the specified URI.

    Declaration
    public Uri(string uriString)
    Parameters
    Type Name Description
    String uriString

    A URI.

    Remarks

    This constructor parses the URI string, therefore it can be used to validate a URI.

    Exceptions
    Type Condition
    ArgumentNullException

    The uriString is null.

    ArgumentException

    The uriString is empty.

    -or-

    The scheme specified in uriString is not correctly formed.

    -or-

    uriString contains too many slashes.

    -or-

    The password specified in uriString is not valid.

    -or-

    The host name specified in uriString is not valid.

    -or-

    The file name specified in uriString is not valid.

    -or-

    The user name specified in uriString is not valid.

    -or-

    The host or authority name specified in uriString cannot be terminated by backslashes.

    -or-

    The port number specified in uriString is not valid or cannot be parsed.

    -or-

    The length of uriString exceeds 65534 characters.

    -or-

    The length of the scheme specified in uriString exceeds 1023 characters.

    -or-

    There is an invalid character sequence in uriString.

    -or-

    The MS-DOS path specified in uriString must start with c:\\.

    | Improve this Doc View Source

    Uri(String, UriKind)

    Constructs Uri from string and enumeration that tell what is the type of Uri.

    Declaration
    public Uri(string uriString, UriKind kind)
    Parameters
    Type Name Description
    String uriString

    String to construct Uri from

    UriKind kind

    Type of Uri to construct

    Exceptions
    Type Condition
    ArgumentException

    The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.

    | Improve this Doc View Source

    Uri(Uri, String)

    Initializes a new instance of the Uri class based on the specified base URI and relative URI String.

    Declaration
    public Uri(Uri baseUri, string relativeUri = null)
    Parameters
    Type Name Description
    Uri baseUri

    The base URI.

    String relativeUri

    The relative URI to add to the base URI.

    Exceptions
    Type Condition
    ArgumentNullException

    baseUri is null.

    ArgumentOutOfRangeException

    baseUri is not an absolute Uri instance.

    FormatException

    The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.

    Fields

    | Improve this Doc View Source

    _AbsolutePath

    Member variable that keeps absolute path.

    Declaration
    protected string _AbsolutePath
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    _absoluteUri

    Member variable that keeps absolute uri (generated in method ParseUriString)

    Declaration
    protected string _absoluteUri
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    _Flags

    Member variable that keeps internal flags/

    Declaration
    protected Uri.Flags _Flags
    Field Value
    Type Description
    Uri.Flags
    | Improve this Doc View Source

    _host

    Member variable that keeps host name ( http and https ).

    Declaration
    protected string _host
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    _hostNameType

    Type of the host.

    Declaration
    protected UriHostNameType _hostNameType
    Field Value
    Type Description
    UriHostNameType
    | Improve this Doc View Source

    _isAbsoluteUri

    Member variable that keeps boolean if Uri is absolute.

    Declaration
    protected bool _isAbsoluteUri
    Field Value
    Type Description
    Boolean
    | Improve this Doc View Source

    _isUnc

    Member variable that tells if path is UNC ( Universal Naming Convention ) In this class it is always false, but can be changed in derived classes.

    Declaration
    protected bool _isUnc
    Field Value
    Type Description
    Boolean
    | Improve this Doc View Source

    _OriginalUriString

    Member variable that keeps original string passed to Uri constructor.

    Declaration
    protected string _OriginalUriString
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    _port

    Member variable that keeps port used by this uri.

    Declaration
    protected int _port
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    _scheme

    Member variable that keeps scheme of Uri.

    Declaration
    protected string _scheme
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    HttpDefaultPort

    Default port for http protocol - 80

    Declaration
    public const int HttpDefaultPort = 80
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    HttpsDefaultPort

    Default port for https protocol - 443

    Declaration
    public const int HttpsDefaultPort = 443
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    UnknownPort

    Constant to indicate that port for this protocol is unknown

    Declaration
    protected const int UnknownPort = -1
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    UriSchemeHttp

    Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). This field is read-only.

    Declaration
    public const string UriSchemeHttp = "http"
    Field Value
    Type Description
    String
    | Improve this Doc View Source

    UriSchemeHttps

    Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS). This field is read-only.

    Declaration
    public const string UriSchemeHttps = "https"
    Field Value
    Type Description
    String

    Properties

    | Improve this Doc View Source

    AbsolutePath

    Gets a local operating-system representation of a file name.

    Declaration
    public string AbsolutePath { get; }
    Property Value
    Type Description
    String

    A String containing the local operating-system representation of a file name.

    Exceptions
    Type Condition
    InvalidOperationException

    This instance represents a relative URI, and this property is valid only for absolute URIs.

    | Improve this Doc View Source

    AbsoluteUri

    Gets a string containing the absolute uri or entire uri of this instance.

    Declaration
    public string AbsoluteUri { get; }
    Property Value
    Type Description
    String

    A String containing the entire URI.

    | Improve this Doc View Source

    Host

    Gets the host component of this instance.

    Declaration
    public string Host { get; }
    Property Value
    Type Description
    String

    A String containing the host name. This is usually the DNS host name or IP address of the server.

    | Improve this Doc View Source

    HostNameType

    Gets the type of the host name specified in the URI.

    Declaration
    public UriHostNameType HostNameType { get; }
    Property Value
    Type Description
    UriHostNameType

    A member of the UriHostNameType enumeration.

    | Improve this Doc View Source

    IsAbsoluteUri

    Gets whether the Uri instance is absolute.

    Declaration
    public bool IsAbsoluteUri { get; }
    Property Value
    Type Description
    Boolean

    true if the Uri instance is absolute; otherwise, false.

    | Improve this Doc View Source

    IsLoopback

    Gets whether the specified Uri refers to the local host.

    Declaration
    public bool IsLoopback { get; }
    Property Value
    Type Description
    Boolean

    true if the host specified in the Uri is the local computer; otherwise, false.

    | Improve this Doc View Source

    IsUnc

    Gets whether the specified Uri is a universal naming convention (UNC) path.

    Declaration
    public bool IsUnc { get; }
    Property Value
    Type Description
    Boolean

    true if the Uri is a UNC path; otherwise, false.

    Exceptions
    Type Condition
    InvalidOperationException

    This instance represents a relative URI, and this property is valid only for absolute URIs.

    | Improve this Doc View Source

    OriginalString

    Gets the original URI string that was passed to the Uri constructor.

    Declaration
    public string OriginalString { get; }
    Property Value
    Type Description
    String
    | Improve this Doc View Source

    Port

    Gets the port number of this URI.

    Declaration
    public int Port { get; }
    Property Value
    Type Description
    Int32

    An Int32 value containing the port number for this URI.

    Exceptions
    Type Condition
    InvalidOperationException

    This instance represents a relative URI, and this property is valid only for absolute URIs.

    | Improve this Doc View Source

    Scheme

    Gets the scheme name for this URI.

    Declaration
    public string Scheme { get; }
    Property Value
    Type Description
    String

    A String containing the scheme for this URI, converted to lowercase.

    Exceptions
    Type Condition
    InvalidOperationException

    This instance represents a relative URI, and this property is valid only for absolute URIs.

    Methods

    | Improve this Doc View Source

    ConstructAbsoluteUri(String)

    Constructs an absolute Uri from a URI string.

    Declaration
    protected bool ConstructAbsoluteUri(string uriString)
    Parameters
    Type Name Description
    String uriString

    A URI.

    Returns
    Type Description
    Boolean
    Remarks

    See Uri(String).

    | Improve this Doc View Source

    Equals(Object)

    Determines whether the specified object is equal to the current object.

    Declaration
    public override bool Equals(object o)
    Parameters
    Type Name Description
    Object o
    Returns
    Type Description
    Boolean

    true if the specified object is equal to the current object; otherwise, false.

    Overrides
    Object.Equals(Object)
    | Improve this Doc View Source

    GetHashCode()

    Serves as the default hash function.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    A hash code for the current object.

    Overrides
    Object.GetHashCode()
    | Improve this Doc View Source

    IsIPv4(String)

    Returns if host name is IP adress 4 bytes. Like 192.1.1.1

    Declaration
    protected bool IsIPv4(string host)
    Parameters
    Type Name Description
    String host

    string with host name

    Returns
    Type Description
    Boolean

    True if name is string with IPv4 address

    | Improve this Doc View Source

    IsWellFormedUriString(String, UriKind)

    Indicates whether the string is well-formed by attempting to construct a URI with the string.

    Declaration
    public static bool IsWellFormedUriString(string uriString, UriKind uriKind)
    Parameters
    Type Name Description
    String uriString

    A URI.

    UriKind uriKind

    The type of the URI in uriString.

    Returns
    Type Description
    Boolean

    true if the string was well-formed in accordance with RFC 2396 and RFC 2732; otherwise false.

    | Improve this Doc View Source

    ParseSchemeSpecificPart(String, Int32)

    Parse Scheme-specific part of uri for host, port and absolute path Briefed syntax abstracted from .NET FX: Group 1 - http, https, ftp, file, gopher, nntp, telnet, ldap, net.tcp and net.pipe Must be rooted. The 1st segment is authority. Empty path should be replace as '/'

    Group 2 - file Reminder: Treat all '' as '/' If it starts with only one '/', host should be empty Otherwise, all leading '/' should be ignored before searching for 1st segment. The 1st segment is host

    Group 3 - news and uuid Authority always be empty. Everything goes to path.

    Group 4 - mailto and all other shemes The 1st segment is authority iff it was not rooted.

    Group 5 - all other schemes The 1st segment is authority iff it was rooted. Empty path should be replace as '/'

    Declaration
    protected bool ParseSchemeSpecificPart(string sUri, int iStart)
    Parameters
    Type Name Description
    String sUri

    Scheme-specific part of uri

    Int32 iStart
    Returns
    Type Description
    Boolean
    | Improve this Doc View Source

    Split(String, Int32, out String, out String, Boolean)

    Declaration
    protected void Split(string sUri, int iStart, out string sAuthority, out string sPath, bool bReplaceEmptyPath)
    Parameters
    Type Name Description
    String sUri
    Int32 iStart
    String sAuthority
    String sPath
    Boolean bReplaceEmptyPath
    | Improve this Doc View Source

    TryParseUriString(String)

    Internal method parses a URI string into Uri variables

    Declaration
    protected bool TryParseUriString(string uriString)
    Parameters
    Type Name Description
    String uriString

    A Uri.

    Returns
    Type Description
    Boolean
    Exceptions
    Type Condition
    ArgumentNullException

    The uriString is null.

    Exception

    See constructor description.

    | Improve this Doc View Source

    ValidateUriPart(String, Int32)

    Validates that part of Uri after sheme is valid for unknown Uri scheme

    Declaration
    protected bool ValidateUriPart(string uriString, int startIndex)
    Parameters
    Type Name Description
    String uriString

    Uri string

    Int32 startIndex

    Index in the string where Uri part ( after scheme ) starts

    Returns
    Type Description
    Boolean

    Operators

    | Improve this Doc View Source

    Equality(Uri, Uri)

    Declaration
    public static bool operator ==(Uri lhs, Uri rhs)
    Parameters
    Type Name Description
    Uri lhs
    Uri rhs
    Returns
    Type Description
    Boolean
    | Improve this Doc View Source

    Inequality(Uri, Uri)

    Declaration
    public static bool operator !=(Uri lhs, Uri rhs)
    Parameters
    Type Name Description
    Uri lhs
    Uri rhs
    Returns
    Type Description
    Boolean

    Extension Methods

    LogDispatcher.GetCurrentClassLogger(Object)
    • Improve this Doc
    • View Source
    Back to top Copyright © 2018 nanoFramework Contributors
    Generated by DocFX