Uri.IdnHost プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
必要に応じて 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、および IPv6 の入力で Host と 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.deはxn--mnchen-3ya.deになります)。 有効な IDN ではないホスト名は、as-is 返され、ASCII 以外の文字が含まれる場合があります。 -
IPv6 アドレスの場合: 周囲の角かっこのないアドレスを返し、ゾーン ID (スコープ) が指定されている場合 (たとえば、
::1またはfe80::1%18) が含まれます。 -
IPv4 アドレスの場合: ドット 10 進表記 (たとえば、
192.168.1.1) を返します。
IdnHost は、従来の DnsSafeHost プロパティに代わる推奨される代替手段です。その動作は app.config 設定に依存せず、DNS 解決に適した値を生成するように設計されているためです。 ゾーン ID を含む IPv6 の結果の場合、呼び出し元はゾーン ID を受け入れない 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 はエスケープされていない文字列を返します。