Uri.IdnHost 속성

정의

적절한 Punycode를 사용하여 호스트의 RFC 3490 호환 국제 도메인 이름을 가져옵니다. 이 문자열은 필요한 경우 이스케이프되지 않은 후 DNS 확인에 안전하게 사용할 수 있습니다.

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

속성 값

IDN 표준에 따라 Punycode로 형식이 지정된 호스트 이름입니다.

예외

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

예제

다음 예제에서는 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

설명

이 속성은 Punycode 형식의 도메인 이름이 필요한 하위 수준 네트워킹 프로토콜을 사용하기 위해 제공됩니다. 코드에 특정 형식이 필요하지 않은 경우 호스트 이름을 사용합니다 Host .

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

  • DNS 호스트 이름: 유효한 국제 도메인 이름의 경우 ASCII가 아닌 문자는 punycode로 인코딩됩니다(예: münchen.dexn--mnchen-3ya.de). 유효한 IDN이 아닌 호스트 이름은 as-is 반환되고 ASCII가 아닌 문자를 포함할 수 있습니다.
  • IPv6 주소의 경우: 주변 대괄호 없이 주소를 반환하고 영역 ID(범위)가 지정된 경우(예::1: )fe80::1%18를 포함합니다.
  • IPv4 주소의 경우: 점선 소수점 표기법(예: 192.168.1.1)을 반환합니다.

IdnHost동작은 DnsSafeHost 설정에 의존하지 않고 DNS 확인에 적합한 값을 생성하도록 설계되었기 때문에 레거시 속성의 기본 대안입니다. 영역 ID를 포함하는 IPv6 결과의 경우 호출자는 해당 값을 수락하지 않는 API에 전달하기 전에 영역 ID를 제거해야 할 수 있습니다.

이스케이프된 문자열을 사용하여 이 인스턴스(예: "http://[fe80::200:39ff:fe36:1a2d%254]/temp/example.htm")를 생성한 경우 IdnHost는 이스케이프된 문자열을 반환합니다. DNS 확인을 위해 해당 문자열을 사용하기 전에 IdnHost에서 반환된 이스케이프된 문자열의 이스케이프를 제거해야 합니다. 이 인스턴스를 생성하기 위해 잘못된 이스케이프되지 않은 문자열을 사용한 경우(예: "http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm") IdnHost는 이스케이프되지 않은 문자열을 반환합니다.

적용 대상