. NET Framework Class Library: URI class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.