Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Uri
Assembly: System.Runtime
Inheritance: object → Uri
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.
Fields and Constants
public static readonly
string
SchemeDelimiter
Specifies the characters that separate the communication protocol scheme from the address portion of the URI. This field is read-only.
public static readonly
string
UriSchemeFile
Specifies that the URI is a pointer to a file. This field is read-only.
public static readonly
string
UriSchemeFtp
Specifies that the URI is accessed through the File Transfer Protocol (FTP). This field is read-only.
public static readonly
string
UriSchemeFtps
Specifies that the URI is accessed through the File Transfer Protocol Secure (FTPS). This field is read-only.
public static readonly
string
UriSchemeGopher
Specifies that the URI is accessed through the Gopher protocol. This field is read-only.
public static readonly
string
UriSchemeHttp
Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). This field is read-only.
public static readonly
string
UriSchemeHttps
Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS). This field is read-only.
public static readonly
string
UriSchemeMailto
Specifies that the URI is an email address and is accessed through the Simple Mail Transport Protocol (SMTP). This field is read-only.
public static readonly
string
UriSchemeNetPipe
Specifies that the URI is accessed through the NetPipe scheme used by Windows Communication Foundation (WCF). This field is read-only.
public static readonly
string
UriSchemeNetTcp
Specifies that the URI is accessed through the NetTcp scheme used by Windows Communication Foundation (WCF). This field is read-only.
public static readonly
string
UriSchemeNews
Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.
public static readonly
string
UriSchemeNntp
Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.
public static readonly
string
UriSchemeSftp
Specifies that the URI is accessed through the SSH File Transfer Protocol (SFTP). This field is read-only.
public static readonly
string
UriSchemeSsh
Specifies that the URI is accessed through the Secure Socket Shell protocol (SSH). This field is read-only.
public static readonly
string
UriSchemeTelnet
Specifies that the URI is accessed through the Telnet protocol. This field is read-only.
public static readonly
string
UriSchemeWs
Specifies that the URI is accessed through the WebSocket protocol (WS). This field is read-only.
public static readonly
string
UriSchemeWss
Specifies that the URI is accessed through the WebSocket Secure protocol (WSS). This field is read-only.
Properties
public
string
AbsolutePath
Gets the absolute path of the URI.
public
string
AbsoluteUri
Gets the absolute URI.
public
string
Authority
Gets the Domain Name System (DNS) host name or IP address and the port number for a server.
public
string
DnsSafeHost
Gets a host name that, after being unescaped if necessary, is safe to use for DNS resolution.
public
string
Fragment
Gets the escaped URI fragment, including the leading '#' character if not empty.
public
string
Host
Gets the host component of this instance.
public
UriHostNameType
HostNameType
Gets the type of the host name specified in the URI.
public
string
IdnHost
Gets the RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate. This string, after being unescaped if necessary, is safe to use for DNS resolution.
public
bool
IsAbsoluteUri
Gets a value that indicates whether the <see cref="T:System.Uri" /> instance is absolute.
public
bool
IsDefaultPort
Gets a value that indicates whether the port value of the URI is the default for this scheme.
public
bool
IsFile
Gets a value that indicates whether the specified <see cref="T:System.Uri" /> is a file URI.
public
bool
IsLoopback
Gets a value that indicates whether the specified <see cref="T:System.Uri" /> references the local host.
public
bool
IsUnc
Gets a value that indicates whether the specified <see cref="T:System.Uri" /> is a universal naming convention (UNC) path.
public
string
LocalPath
Gets a local operating-system representation of a file name.
public
string
OriginalString
Gets the original URI string that was passed to the <see cref="T:System.Uri" /> constructor.
public
string
PathAndQuery
Gets the <see cref="P:System.Uri.AbsolutePath" /> and <see cref="P:System.Uri.Query" /> properties separated by a question mark (?).
public
int
Port
Gets the port number of this URI.
public
string
Query
Gets any query information included in the specified URI, including the leading '?' character if not empty.
public
string
Scheme
Gets the scheme name for this URI.
public
string[]
Segments
Gets an array containing the path segments that make up the specified URI.
public
bool
UserEscaped
Gets a value that indicates whether the URI string was completely escaped before the <see cref="T:System.Uri" /> instance was created.
public
string
UserInfo
Gets the user name, password, or other user-specific information associated with the specified URI.
Methods
protected
void
Canonicalize​()
Converts the internally stored URI to canonical form.
protected
void
CheckSecurity​()
Calling this method has no effect.
public
bool
Equals​(object comparand)
comparand
The URI or a URI identifier to compare with the current instance.
Returns <see langword="true" /> if the two instances represent the same URI; otherwise, <see langword="false" /> .
Compares two <see cref="T:System.Uri" /> instances for equality.
public
bool
Equals​(Uri other)
other
The <see cref="T:System.Uri" /> to compare to this instance.
Returns <see langword="true" /> if the two instances represent the same URI; otherwise, <see langword="false" /> .
Compares two <see cref="T:System.Uri" /> instances for equality.
protected
void
Escape​()
Converts any unsafe or reserved characters in the path component to their hexadecimal character representations.
public
string
GetComponents​(UriComponents components,
UriFormat format)
components
A bitwise combination of the <see cref="T:System.UriComponents" /> values that specifies which parts of the current instance to return to the caller.
format
One of the enumeration values that controls how special characters are escaped.
Returns The components of the current instance.
Gets the specified components of the current instance using the specified escaping for special characters.
public
int
GetHashCode​() Returns The hash value generated for this URI.
Gets the hash code for the URI.
public
string
GetLeftPart​(UriPartial part)
part
One of the enumeration values that specifies the end of the URI portion to return.
Returns The specified portion of the <see cref="T:System.Uri" /> instance.
Gets the specified portion of a <see cref="T:System.Uri" /> instance.
protected
void
GetObjectData​(SerializationInfo serializationInfo,
StreamingContext streamingContext)
serializationInfo
The information required to serialize the <see cref="T:System.Uri" /> .
streamingContext
An object that contains the source and destination of the serialized stream associated with the <see cref="T:System.Uri" /> .
Returns the data needed to serialize the current instance.
protected
bool
IsBadFileSystemCharacter​(char character)
character
The <see cref="T:System.Char" /> to test.
Returns <see langword="true" /> if the specified character is invalid; otherwise, <see langword="false" /> .
Indicates whether a character is invalid in a file system name.
public
bool
IsBaseOf​(Uri uri)
uri
The specified URI to test.
Returns <see langword="true" /> if the current <see cref="T:System.Uri" /> instance is a base of <paramref name="uri" /> ; otherwise, <see langword="false" /> .
Determines whether the current <see cref="T:System.Uri" /> instance is a base of the specified <see cref="T:System.Uri" /> instance.
protected
bool
IsReservedCharacter​(char character)
character
The character to test.
Returns <see langword="true" /> if the specified character is a reserved character otherwise, <see langword="false" /> .
Determines whether the specified character is a reserved character.
public
bool
IsWellFormedOriginalString​() Returns <see langword="true" /> if the string was well-formed; otherwise, <see langword="false" /> .
Indicates whether the string used to construct this <see cref="T:System.Uri" /> was well-formed and does not require further escaping.
public
string
MakeRelative​(Uri toUri)
toUri
The URI to compare to the current URI.
Returns If the hostname and scheme of this URI instance and <paramref name="toUri" /> are the same, then this method returns a <see cref="T:System.String" /> that represents a relative URI that, when appended to the current URI instance, yields the <paramref name="toUri" /> parameter.
If the hostname or scheme is different, then this method returns a <see cref="T:System.String" /> that represents the <paramref name="toUri" /> parameter.
Determines the difference between two <see cref="T:System.Uri" /> instances.
public
Uri
MakeRelativeUri​(Uri uri)
uri
The URI to compare to the current URI.
Returns If the hostname and scheme of this URI instance and <paramref name="uri" /> are the same, then this method returns a relative <see cref="T:System.Uri" /> that, when appended to the current URI instance, yields <paramref name="uri" /> .
If the hostname or scheme is different, then this method returns a <see cref="T:System.Uri" /> that represents the <paramref name="uri" /> parameter.
Determines the difference between two <see cref="T:System.Uri" /> instances.
protected
void
Parse​()
Parses the URI of the current instance to ensure it contains all the parts required for a valid URI.
public
string
ToString​() Returns The unescaped canonical representation of the <see cref="T:System.Uri" /> instance. All characters are unescaped except #, ?, and %.
Gets a canonical string representation for the specified <see cref="T:System.Uri" /> instance.
protected
string
Unescape​(string path)
path
The string to convert.
Returns The unescaped value of the <paramref name="path" /> parameter.
Converts the specified string by replacing any escape sequences with their unescaped representation.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .