System Namespace
Provides an object representation of a uniform resource indentifier ( URI ) and easy access to the parts of the URI.
Visibility |
Name |
Parameters |
Return Type |
protected |
Canonicalize |
( )
|
Void
|
public static |
CheckHostName |
(
String
name
)
|
UriHostNameType
|
public static |
CheckSchemeName |
(
String
schemeName
)
|
Boolean
|
protected |
CheckSecurity |
( )
|
Void
|
public static |
Compare |
(
Uri
uri1
,
Uri
uri2
,
UriComponents
partsToCompare
,
UriFormat
compareFormat
,
StringComparison
comparisonType
)
|
Int32
|
public |
Equals |
(
Object
comparand
)
|
Boolean
|
protected |
Escape |
( )
|
Void
|
public static |
EscapeDataString |
(
String
stringToEscape
)
|
String
|
protected static |
EscapeString |
(
String
str
)
|
String
|
public static |
EscapeUriString |
(
String
stringToEscape
)
|
String
|
public static |
FromHex |
(
Char
digit
)
|
Int32
|
public |
GetComponents |
(
UriComponents
components
,
UriFormat
format
)
|
String
|
public |
GetHashCode |
( )
|
Int32
|
public |
GetLeftPart |
(
UriPartial
part
)
|
String
|
protected |
GetObjectData |
(
SerializationInfo
serializationInfo
,
StreamingContext
streamingContext
)
|
Void
|
public static |
HexEscape |
(
Char
character
)
|
String
|
public static |
HexUnescape |
(
String
pattern
,
Int32&
index
)
|
Char
|
protected |
IsBadFileSystemCharacter |
(
Char
character
)
|
Boolean
|
public |
IsBaseOf |
(
Uri
uri
)
|
Boolean
|
protected static |
IsExcludedCharacter |
(
Char
character
)
|
Boolean
|
public static |
IsHexDigit |
(
Char
character
)
|
Boolean
|
public static |
IsHexEncoding |
(
String
pattern
,
Int32
index
)
|
Boolean
|
protected |
IsReservedCharacter |
(
Char
character
)
|
Boolean
|
public |
IsWellFormedOriginalString |
( )
|
Boolean
|
public static |
IsWellFormedUriString |
(
String
uriString
,
UriKind
uriKind
)
|
Boolean
|
public |
MakeRelative |
(
Uri
toUri
)
|
String
|
public |
MakeRelativeUri |
(
Uri
uri
)
|
Uri
|
protected |
Parse |
( )
|
Void
|
public |
ToString |
( )
|
String
|
public static |
TryCreate |
(
Uri
baseUri
,
String
relativeUri
,
Uri&
result
)
|
Boolean
|
public static |
TryCreate |
(
Uri
baseUri
,
Uri
relativeUri
,
Uri&
result
)
|
Boolean
|
public static |
TryCreate |
(
String
uriString
,
UriKind
uriKind
,
Uri&
result
)
|
Boolean
|
protected |
Unescape |
(
String
path
)
|
String
|
public static |
UnescapeDataString |
(
String
stringToUnescape
)
|
String
|
|
A URI is a compact representation of a resource available to your application on the Internet. The Uri class defines the properties and methods for handling URIs, including parsing, comparing, and combining. The Uri class properties are read-only, to modify a Uri instance use the UriBuilder class.
The Uri class stores only absolute URIs ( for example, "http://www.contoso.com/index.aspx" ). Relative URIs ( for example, "/new/index.aspx" ) must be expanded with respect to a base URI so that they are absolute. The MakeRelative method is provided to convert absolute URIs to relative URIs when necessary.
The Uri constructors will not escape URI strings if the string is a well-formed URI including a scheme identifier that contains escape sequences. The constructors will escape relative URI strings that contain a percent sign ( % ).
URIs are stored as canonical URIs in escaped encoding, with all characters with ASCII values greater than 127 replaced with their hexidecimal equivalents. To put the URI in canonical form, the Uri constructor performs the following steps.
- Converts the URI scheme to lower case.
- Converts the host name to lower case.
- Removes default and empty port numbers.
- Simplifies the URI by removing superfluous segments such as "/" and "/test" segments.
You can transform the contents of the Uri class from an escape encoded URI reference to a readable URI reference using the ToString method.
Some URIs include a fragment identifier or query. A fragment identifier is any text that follows a number sign ( # ) in the URI and is stored in the Fragment property. Query information is any text that follows a question mark ( ? ) in the URI, and is stored in the Query property.
The following example creates an instance of the Uri class and uses it to create a WebRequest.
[ VB ]
Dim siteUri As New Uri ( "http://www.contoso.com/" )
Dim wr As WebRequest = WebRequest.Create ( siteUri )
[ C# ]
Uri siteUri = new Uri ( "http://www.contoso.com/" );
WebRequest wr = WebRequest.Create ( siteUri );
UriBuilder