언어

Uri.Host 속성

정의

이 인스턴스의 호스트 구성 요소를 가져옵니다.

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

속성 값

호스트 이름입니다. 일반적으로 서버의 DNS 호스트 이름 또는 IP 주소입니다.

예외

이 인스턴스는 상대 URI를 나타내며 이 속성은 절대 URI에 대해서만 유효합니다.

예제

다음 예제에서는 서버의 호스트 이름(www.contoso.com)을 콘솔에 씁니다.

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

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

printfn $"{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)

다음 예제에서는 DNS, IDN, IPv4 및 Host IPv6 입력 간에 차이점 IdnHost 을 보여 줍니다.

// Demonstrate differences between Host, IdnHost, and DnsSafeHost.

// Example 1: Regular hostname (ASCII).
Console.WriteLine("Example 1: Regular ASCII hostname");
Uri uri1 = new Uri("http://www.contoso.com:8080/path");
Console.WriteLine($"  Host:        {uri1.Host}");        // www.contoso.com
Console.WriteLine($"  IdnHost:     {uri1.IdnHost}");     // www.contoso.com
Console.WriteLine($"  DnsSafeHost: {uri1.DnsSafeHost}"); // www.contoso.com
Console.WriteLine();

// Example 2: International domain name (non-ASCII).
Console.WriteLine("Example 2: International domain name");
Uri uri2 = new Uri("http://münchen.de/path");
Console.WriteLine($"  Host:        {uri2.Host}");        // münchen.de (original)
Console.WriteLine($"  IdnHost:     {uri2.IdnHost}");     // xn--mnchen-3ya.de (punycode)
Console.WriteLine($"  DnsSafeHost: {uri2.DnsSafeHost}"); // münchen.de or xn--mnchen-3ya.de, depending on configuration.
Console.WriteLine();

// Example 3: International domain name already in punycode (encoded) form.
Console.WriteLine("Example 3: Already-encoded international domain name");
Uri uri2Encoded = new Uri("http://xn--mnchen-3ya.de/path");
Console.WriteLine($"  Host:        {uri2Encoded.Host}");        // xn--mnchen-3ya.de (as provided)
Console.WriteLine($"  IdnHost:     {uri2Encoded.IdnHost}");     // xn--mnchen-3ya.de (already punycode)
Console.WriteLine($"  DnsSafeHost: {uri2Encoded.DnsSafeHost}"); // xn--mnchen-3ya.de
Console.WriteLine();

// Example 4: IPv6 address without zone ID.
Console.WriteLine("Example 4: IPv6 address without zone ID");
Uri uri3 = new Uri("http://[::1]:8080/path");
Console.WriteLine($"  Host:        {uri3.Host}");        // [::1] (with brackets)
Console.WriteLine($"  IdnHost:     {uri3.IdnHost}");     // ::1 (without brackets)
Console.WriteLine($"  DnsSafeHost: {uri3.DnsSafeHost}"); // ::1 (without brackets)
Console.WriteLine();

// Example 5: IPv6 link-local address with zone ID.
Console.WriteLine("Example 5: IPv6 link-local address with zone ID");
Uri uri4 = new Uri("http://[fe80::1%10]:8080/path");
Console.WriteLine($"  Host:        {uri4.Host}");        // [fe80::1] (with brackets, no zone ID)
Console.WriteLine($"  IdnHost:     {uri4.IdnHost}");     // fe80::1%10 (without brackets, with zone ID)
Console.WriteLine($"  DnsSafeHost: {uri4.DnsSafeHost}"); // fe80::1%10 (without brackets, with zone ID)
Console.WriteLine();

// Example 6: IPv4 address.
Console.WriteLine("Example 6: IPv4 address");
Uri uri5 = new Uri("http://192.168.1.1:8080/path");
Console.WriteLine($"  Host:        {uri5.Host}");        // 192.168.1.1
Console.WriteLine($"  IdnHost:     {uri5.IdnHost}");     // 192.168.1.1
Console.WriteLine($"  DnsSafeHost: {uri5.DnsSafeHost}"); // 192.168.1.1

설명

속성과 Authority 달리 이 속성 값에는 포트 번호가 포함되지 않습니다.

이 속성에서 반환되는 값은 호스트 유형에 따라 달라집니다.

  • DNS 호스트 이름(국가별 도메인 이름 포함):이스케이프된 입력을 반환합니다. ASCII가 아닌 문자는 as-is 반환되며 punycode로 인코딩되지 않습니다.
  • IPv6 주소의 경우: 대괄호(예: 대괄호)로 [::1]묶인 주소를 반환하지만 원래 URI에 지정된 경우에도 영역 ID(범위)는 포함하지 않습니다.
  • IPv4 주소의 경우: 점선 소수점 표기법(예: 192.168.1.1)을 반환합니다.

DNS 확인 또는 기타 하위 수준 네트워킹 시나리오의 경우 유효한 국제 도메인 이름에 대해 punycode로 인코딩된 양식을 반환하고 IPv6 주소에 대한 영역 ID(대괄호 제외)를 포함하는 대신 사용합니다 IdnHost . 호스트가 URI에 표시되기를 원할 때 사용합니다 Host (예: 표시 또는 비교).

적용 대상