-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Refine Uri Host property documentation: clarify IdnHost behavior and focus on Host/IdnHost #12301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e5679d7
67108dd
946ce15
3d59079
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| using System; | ||
|
|
||
| public class UriHostComparison | ||
| { | ||
| public static void Main() | ||
| { | ||
| // <SnippetHostComparison> | ||
| // 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 | ||
| Console.WriteLine(); | ||
|
Comment on lines
+18
to
+24
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot Also include an example where the input is already an encoded host (xn--mnchen-3ya.de)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added Example 3 covering a URI whose host is already in punycode ( |
||
|
|
||
| // 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) | ||
|
MihaZupan marked this conversation as resolved.
|
||
| 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 | ||
|
MihaZupan marked this conversation as resolved.
|
||
| // </SnippetHostComparison> | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.