Class Uri
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.
Inherited Members
Namespace: System
Assembly: System.Net.Http.dll
Syntax
public class Uri
Constructors
| Improve this Doc View SourceUri(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 |
ArgumentException | The -or- The scheme specified in -or-
-or- The password specified in -or- The host name specified in
-or- The file name specified in
-or- The user name specified in
-or- The host or authority name specified in
-or- The port number specified in
-or- The length of -or- The length of the scheme specified in
-or- There is an invalid character sequence in
-or- The MS-DOS path specified in
|
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 |
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 |
|
ArgumentOutOfRangeException |
|
FormatException | The scheme specified in the URI formed by combining |
Fields
| Improve this Doc View Source_AbsolutePath
Member variable that keeps absolute path.
Declaration
protected string _AbsolutePath
Field Value
Type | Description |
---|---|
String |
_absoluteUri
Member variable that keeps absolute uri (generated in method ParseUriString)
Declaration
protected string _absoluteUri
Field Value
Type | Description |
---|---|
String |
_Flags
Member variable that keeps internal flags/
Declaration
protected Uri.Flags _Flags
Field Value
Type | Description |
---|---|
Uri.Flags |
_host
Member variable that keeps host name ( http and https ).
Declaration
protected string _host
Field Value
Type | Description |
---|---|
String |
_hostNameType
Type of the host.
Declaration
protected UriHostNameType _hostNameType
Field Value
Type | Description |
---|---|
UriHostNameType |
_isAbsoluteUri
Member variable that keeps boolean if Uri is absolute.
Declaration
protected bool _isAbsoluteUri
Field Value
Type | Description |
---|---|
Boolean |
_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 |
_OriginalUriString
Member variable that keeps original string passed to Uri constructor.
Declaration
protected string _OriginalUriString
Field Value
Type | Description |
---|---|
String |
_port
Member variable that keeps port used by this uri.
Declaration
protected int _port
Field Value
Type | Description |
---|---|
Int32 |
_scheme
Member variable that keeps scheme of Uri.
Declaration
protected string _scheme
Field Value
Type | Description |
---|---|
String |
HttpDefaultPort
Default port for http protocol - 80
Declaration
public const int HttpDefaultPort = 80
Field Value
Type | Description |
---|---|
Int32 |
HttpsDefaultPort
Default port for https protocol - 443
Declaration
public const int HttpsDefaultPort = 443
Field Value
Type | Description |
---|---|
Int32 |
UnknownPort
Constant to indicate that port for this protocol is unknown
Declaration
protected const int UnknownPort = -1
Field Value
Type | Description |
---|---|
Int32 |
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 |
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 SourceAbsolutePath
Gets a local operating-system representation of a file name.
Declaration
public string AbsolutePath { get; }
Property Value
Type | Description |
---|---|
String | A |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This instance represents a relative URI, and this property is valid only for absolute URIs. |
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 |
Host
Gets the host component of this instance.
Declaration
public string Host { get; }
Property Value
Type | Description |
---|---|
String | A |
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. |
IsAbsoluteUri
Gets whether the Uri instance is absolute.
Declaration
public bool IsAbsoluteUri { get; }
Property Value
Type | Description |
---|---|
Boolean |
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. |
IsUnc
Gets whether the specified Uri is a universal naming convention (UNC) path.
Declaration
public bool IsUnc { get; }
Property Value
Type | Description |
---|---|
Boolean |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This instance represents a relative URI, and this property is valid only for absolute URIs. |
OriginalString
Gets the original URI string that was passed to the Uri constructor.
Declaration
public string OriginalString { get; }
Property Value
Type | Description |
---|---|
String |
Port
Gets the port number of this URI.
Declaration
public int Port { get; }
Property Value
Type | Description |
---|---|
Int32 | An |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This instance represents a relative URI, and this property is valid only for absolute URIs. |
Scheme
Gets the scheme name for this URI.
Declaration
public string Scheme { get; }
Property Value
Type | Description |
---|---|
String | A |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This instance represents a relative URI, and this property is valid only for absolute URIs. |
Methods
| Improve this Doc View SourceConstructAbsoluteUri(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).
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
| Improve this Doc View SourceGetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for the current object. |
Overrides
| Improve this Doc View SourceIsIPv4(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 |
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
|
Returns
Type | Description |
---|---|
Boolean |
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 |
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 |
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 |
Exception | See constructor description. |
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 SourceEquality(Uri, Uri)
Declaration
public static bool operator ==(Uri lhs, Uri rhs)
Parameters
Type | Name | Description |
---|---|---|
Uri | lhs | |
Uri | rhs |
Returns
Type | Description |
---|---|
Boolean |
Inequality(Uri, Uri)
Declaration
public static bool operator !=(Uri lhs, Uri rhs)
Parameters
Type | Name | Description |
---|---|---|
Uri | lhs | |
Uri | rhs |
Returns
Type | Description |
---|---|
Boolean |