Mono Class Library: System NamespaceSystem.Uri Class |
See Also: Uri Members
|
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
Note:A Uniform Resource Identifier (URI) is a compact string of characters used to identify a resource located on a computer. A resource can be anything that has identity. Examples of resources that might be accessed using a URI include an electronic document, an image, a web service, and a collection of other resources. A URI is represented as a sequence of characters. While the exact format of a URI is determined by the protocol used to access the resource, many URI consist of four major components:
<scheme>://<authority><path>?<query>
Scheme - Indicates a protocol used to access the resource.
Authority - Indicates the naming authority (server or registry) that governs the namespace defined by the remainder of the URI. The authority component is composed of userinfo, host and port subcomponents in the form <userinfo>@<host>:<port>. Only the host subcomponent is required to be present in the Authority component. Authority information is stored in the Uri.Authority property.
Path - Identifies the resource within the scope of the scheme and, if present, the authority. This information is stored in the Uri.AbsolutePath , Uri.PathAndQuery, and Uri.LocalPath properties.
Query - Parameter information that is passed to the executable script identified by the URI. The query, if present, is the last element in a URI and begins with a "?". This information is stored in the Uri.Query property.
Userinfo - [Subcomponent of Authority] Consists of a user name and, optionally, scheme-specific authorization information used to access Host . The userinfo, if present, is separated from the Host component by the "@" character. Note that for some URI schemes, the format of the userinfo subcomponent is "username:password". Passing authorization information in this manner is strongly discouraged due to security issues. The userinfo information is stored in the Uri.UserInfo property.
Host - [Subcomponent of Authority] The Domain Name system (DNS) name or IP4 address of a machine that provides access to the resource. This information is stored in the Uri.Host property.
Port - [Subcomponent of Authority ] The network port number used to connect to the host. If no port number is specified in the URI, most schemes designate protocols that have a default port number. This information is stored in the Uri.Port property.
Fragment - The fragment is not part of the URI, but is used in conjunction with the URI and is included here for completeness. This component contains resource-specific information that is used after a resource is retrieved. The fragment , if present, is separated from the URI by the "#" character. This information is stored in the Uri.Fragment property.
URIs include components consisting of or delimited by certain special (reserved) characters that have a special meaning in a URI component. If the reserved meaning is not intended, then the character is required to be escaped in the URI. An escaped character is encoded as a character triplet consisting of the percent character "%" followed by the US-ASCII character code specified as two hexadecimal digits. For example, "%20" is the escaped encoding for the US-ASCII space character. The URI represented by a Uri instance is always in "escaped" form. The following characters are reserved:
- Semi-colon (";" )
- Forward slash ( "/")
- Question mark ( "?" )
- Colon ( ":" )
- At-sign ("@")
- Ampersand ( "&" )
- Equal sign ("=" )
- Plus sign ("+" )
- US Dollar sign ("$" )
- Comma (",")
To transform the URI contained in a Uri instance from an escape encoded URI to a human-readable URI, use the Uri.ToString method.
URIs are stored as canonical URIs in escaped encoding, with all characters with ASCII values greater than 127 replaced with their hexadecimal equivalents. The Uri constructors do not escape URI strings if the string is a well-formed URI, including a scheme identifier, that contains escape sequences. To put the URI in canonical form, the Uri constructors perform the following steps.
- Converts the URI scheme to lowercase.
- Converts the host name to lowercase.
- Removes default and empty port numbers.
- Simplifies the URI by removing superfluous segments such as "/" and "/test" segments.
The Uri class stores only absolute URIs (for example, "http://www.contoso.com/index.htm"). Relative URIs (for example, "/new/index.htm") are expanded to absolute form using a specified base URI. The Uri.MakeRelative(Uri) method converts absolute URIs to relative URIs.
The Uri class properties are read-only; to modify a Uri instance use the UriBuilder class.
[Edit]
Namespace: System
Assembly: System (in System.dll)
Assembly Versions: 1.0.x.x, 1.0.5000.0, 2.0.0.0