Uri.Authority Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the Domain Name System (DNS) host name or IP address and the port number for a server.

Namespace:   System
Assembly:  System (in System.dll)

public string Authority { get; }

Property Value

Type: System.String

A String containing the authority component of the URI represented by this instance.

Exception Condition
InvalidOperationException

This instance represents a relative URI, and this property is valid only for absolute URIs.

The Authority property is typically a server DNS host name or IP address. This property might include the service port number if it differs from the default port for the URI. If the Authority component contains reserved characters, these are escaped in the string value returned by this property.

The following example writes the host name (www.contoso.com) and port number (8080) of the server to the console.

Uri baseUri = new Uri("http://www.contoso.com:8080/");
Uri myUri = new Uri(baseUri,"shownew.htm?date=today");

Console.WriteLine(myUri.Authority);

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show: