Provides a uniform resource identifier (URI) Object Representation and easy access to each part of the URI.
Namespace:System
ProgramSet:System (in system. dll)
Syntax: C #
1[Serializableattribute]
2Public ClassUri: iserializable
Remarks
Uri is a simple representation of resources that can be used by applications on the Intranet or the Internet.UriClass defines attributes and methods to process Uris, including analysis, comparison, and combination.UriThe class attributes are read-only. To create modifiable objects, use the uribuilder class.
Relative uri (for example, "/New/index.htm") must be expanded relative to the base URI. This is absolute. Provides the makerelative method to convert an absolute URI to a relative URI when necessary.
If the URI string is a well-formatted Uri and contains a scheme identifier,UriThe constructor will not escape the URI string.
UriThe attribute returns the canonicalized data representation using escape encoding. Any character with a unicode value greater than 127 will be replaced with an equivalent hexadecimal number. To make the URI have a canonicalized format,UriThe constructor performs the following steps:
Convert the URI scheme to lowercase.
Convert the host name to lowercase. If the host name is an IPv6 address, the normalized IPv6 address is used. Scopeid and other optional IPv6 data will be removed from the default port number and empty port number. Normalize the hierarchical URI path by compressing sequences such as //, //, and // (including escape representation.
For a layered Uri, if the host does not end with a forward slash (/), add a forward slash.
Any reserved characters in the URI must be escaped according to RFC 2396.
Use the tostring methodUriClass content is converted from the URI reference of the escape code to a readable URI reference. Note thatTostringSome Reserved characters in the method output may still be escaped. This is to support ExploitationTostringThe returned value re-constructs the URI without any errors.
Some Uris include a segment identifier, a query, or both. The fragment identifier is any text that follows the numeric symbol (#) (excluding the numeric symbol itself); the paragraph text is stored in the fragment attribute. The query information is followed by the question mark (?) in the URI (?) Any text after; query text is stored in the query attribute.
In. NET Framework 1.1, if the string specified to the constructor contains an unknown scheme and "C: \", the URI class inserts "//" after the colon. For example, UriXYZ: C: \ ABCWill be convertedXYZ: // C:/ABC. This line has been removed from. NET Framework 2.0, and the sample string is convertedXYZ: C:/ABC.
Note: |
The URI class supports IP addresses in the following format: IPv4 protocol in four groups of notation and hexadecimal IPv6 protocol separated by colons. Remember to enclose the brackets on both sides of the IPv6 address, such as http: // [: 1]. |
Example:
C # 1 Uri siteuri = New Uri ( " Http://www.contoso.com/ " );
2
3 Webrequest WR = Webrequest. Create (siteuri );
Inheritance level system. Object
System. Uri