This documentation is archived and is not being maintained.

Uri Class

Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.

For a list of all members of this type, see Uri Members.


[Visual Basic]
Public Class Uri
   Inherits MarshalByRefObject
   Implements ISerializable
public class Uri : MarshalByRefObject, ISerializable
public __gc class Uri : public MarshalByRefObject, ISerializable
class Uri extends MarshalByRefObject implements

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


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 create a modifiable object, use the UriBuilder class.

The Uri class stores only absolute URIs (for example, ""). Relative URIs (for example, "/new/index.htm") 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 (%).

URI properties return a canonical data representation 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. Query information is any text that follows a question mark (?) in the URI; the query text is stored in the Query property.

Note   The URI class supports the use of IP addresses in both quad-notation for IPv4 protocol and colon-hexadecimal for IPv6 protocol. Remember to enclose the IPv6 address in square brackets, as in http://[::1].

.NET Compact Framework Platform Note:  The .NET Compact Framework processes URI strings prefixed by the file:// scheme differently from the full .NET Framework. A relative file://myfile specification resolves as \\myfile. Using file:///myfile (three slashes) resolves as\myfile in the root directory. To ensure successful operations, specify absolute path information.


The following example creates an instance of the Uri class and uses it to create a WebRequest.

[Visual Basic] 
Dim siteUri As New Uri("")
Dim wr As WebRequest = WebRequest.Create(siteUri)

Uri siteUri = new Uri("");
 WebRequest wr = WebRequest.Create(siteUri);

Uri* siteUri = new Uri(S"");
WebRequest* wr = WebRequest::Create(siteUri);

var siteUri : Uri = new Uri("");
var wr : WebRequest = WebRequest.Create(siteUri);


Namespace: System

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System (in System.dll)

See Also

Uri Members | System Namespace | UriBuilder