Uri.Host Uri.Host Uri.Host Uri.Host Property

定义

获取此实例的主机部分。Gets the host component of this instance.

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

属性值

一个包含主机名的 StringA String that contains the host name. 这通常是服务器的 DNS 主机名或 IP 地址。This is usually the DNS host name or IP address of the server.

异常

此实例代表一个相对 URI,而此属性仅对绝对 URI 有效。This instance represents a relative URI, and this property is valid only for absolute URIs.

示例

下面的示例将服务器的主机名www.contoso.com() 写入控制台。The following example writes the host name (www.contoso.com) 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->Host );
Uri baseUri = new Uri("http://www.contoso.com:8080/");
Uri myUri = new Uri(baseUri, "shownew.htm?date=today");
 
 Console.WriteLine(myUri.Host);
   
Dim baseUri As New Uri("http://www.contoso.com:8080/")
Dim myUri As New Uri(baseUri,"shownew.htm?date=today")
       
Console.WriteLine(myUri.Host)

注解

Authority与属性不同, 此属性值不包括端口号。Unlike the Authority property, this property value does not include the port number.

适用于