Uri.Authority Property

Definition

取得伺服器的網域名稱系統 (DNS) 主機名稱或 IP 位址,以及連接埠編號。Gets the Domain Name System (DNS) host name or IP address and the port number for a server.

public:
 property System::String ^ Authority { System::String ^ get(); };
public string Authority { get; }
member this.Authority : string
Public ReadOnly Property Authority As String

Property Value

String

String,包含這個執行個體所代表之 URI 的授權元件。A String containing the authority component of the URI represented by this instance.

Exceptions

這個執行個體代表相對的 URI,而這個屬性只適用於絕對 URI。This instance represents a relative URI, and this property is valid only for absolute URIs.

Examples

下列範例會將伺服器的主機名稱(www.contoso.com)和埠號碼(8080)寫入主控台。The following example writes the host name (www.contoso.com) and port number (8080) of the server to the console.

Uri^ baseUri = gcnew Uri( "http://www.contoso.com:8080/" );
Uri^ myUri = gcnew Uri( baseUri,"shownew.htm?date=today" );
Console::WriteLine( myUri->Authority );
Uri baseUri = new Uri("http://www.contoso.com:8080/");
Uri myUri = new Uri(baseUri,"shownew.htm?date=today");

Console.WriteLine(myUri.Authority);

Dim baseUri As New Uri("http://www.contoso.com:8080/")
Dim myUri As New Uri(baseUri,"shownew.htm?date=today")
       
Console.WriteLine(myUri.Authority)

Remarks

Authority 屬性通常是伺服器 DNS 主機名稱或 IP 位址。The Authority property is typically a server DNS host name or IP address. 如果此屬性與 URI 的預設通訊埠不同,則可能會包含服務埠號碼。This property might include the service port number if it differs from the default port for the URI. 如果 Authority 元件包含保留的字元,這些會在此屬性所傳回的字串值中進行轉義。If the Authority component contains reserved characters, these are escaped in the string value returned by this property.

Applies to