Skip to content

Commit d67ef0d

Browse files
CopilotMihaZupan
andcommitted
Refine Host documentation: C#-only examples, clarify IdnHost behavior
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
1 parent 2ef2e87 commit d67ef0d

6 files changed

Lines changed: 18 additions & 142 deletions

File tree

snippets/csharp/System/Uri/HostComparison/source.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void Main()
2020
Uri uri2 = new Uri("http://münchen.de/path");
2121
Console.WriteLine($" Host: {uri2.Host}"); // münchen.de (original)
2222
Console.WriteLine($" IdnHost: {uri2.IdnHost}"); // xn--mnchen-3ya.de (punycode)
23-
Console.WriteLine($" DnsSafeHost: {uri2.DnsSafeHost}"); // depends on configuration
23+
Console.WriteLine($" DnsSafeHost: {uri2.DnsSafeHost}"); // münchen.de
2424
Console.WriteLine();
2525

2626
// Example 3: IPv6 address without zone ID.

snippets/fsharp/System/Uri/HostComparison/HostComparison.fsproj

Lines changed: 0 additions & 10 deletions
This file was deleted.

snippets/fsharp/System/Uri/HostComparison/source.fs

Lines changed: 0 additions & 44 deletions
This file was deleted.

snippets/visualbasic/System/Uri/HostComparison/HostComparison.vbproj

Lines changed: 0 additions & 7 deletions
This file was deleted.

snippets/visualbasic/System/Uri/HostComparison/source.vb

Lines changed: 0 additions & 48 deletions
This file was deleted.

xml/System/Uri.xml

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,15 +1564,12 @@ If you used an escaped string to construct this instance (for example, `"http://
15641564
15651565
## Comparison with other Host properties
15661566
1567-
The <xref:System.Uri> class provides three host properties that serve different purposes:
1567+
The <xref:System.Uri> class provides two main host properties:
15681568
1569-
- <xref:System.Uri.Host%2A>: Returns the escaped input as provided in the URI. For IPv6, includes brackets but not the zone ID.
1570-
- <xref:System.Uri.IdnHost%2A>: Returns a DNS-safe representation. Non-ASCII hostnames are punycode encoded. For IPv6, doesn't include brackets but does include the zone ID.
1571-
- <xref:System.Uri.DnsSafeHost%2A>: Legacy property that behaves similarly to <xref:System.Uri.IdnHost%2A> but depends on app configuration. Use <xref:System.Uri.IdnHost%2A> instead.
1569+
- <xref:System.Uri.Host%2A>: Returns the host as it appears in the URI. For IPv6, includes brackets but not the zone ID.
1570+
- <xref:System.Uri.IdnHost%2A>: Returns a format suitable for DNS resolution. For valid international domain names, applies punycode encoding. For IPv6, doesn't include brackets but does include the zone ID.
15721571
1573-
Which property to use depends on your scenario:
1574-
- Use <xref:System.Uri.Host%2A> when you need the original host string as it appears in the URI (for display or comparison).
1575-
- Use <xref:System.Uri.IdnHost%2A> when you need a DNS-safe format (for DNS resolution or APIs that require punycode).
1572+
The <xref:System.Uri.DnsSafeHost%2A> property is a legacy property that depends on configuration settings. Use <xref:System.Uri.IdnHost%2A> instead for consistent, configuration-independent behavior.
15761573
15771574
The <xref:System.Uri.DnsSafeHost%2A> property is dependent on configuration settings in .NET Framework apps, as discussed later in this topic. The <xref:System.Uri.IdnHost%2A> property is provided as the preferred alternative to using <xref:System.Uri.DnsSafeHost%2A> because <xref:System.Uri.IdnHost%2A> is guaranteed to always be DNS safe.
15781575
@@ -1624,12 +1621,6 @@ If you used an escaped string to construct this instance (for example, `"http://
16241621
16251622
As explained in Remarks, unescape the host name before resolving it. You can use the <xref:System.Uri.UnescapeDataString%2A> method to unescape the host name, and you can resolve it by calling the <xref:System.Net.Dns.GetHostEntry%2A> method.
16261623
1627-
The following example demonstrates the differences between <xref:System.Uri.Host%2A>, <xref:System.Uri.IdnHost%2A>, and <xref:System.Uri.DnsSafeHost%2A> for various URI types:
1628-
1629-
:::code language="csharp" source="~/snippets/csharp/System/Uri/HostComparison/source.cs" id="SnippetHostComparison":::
1630-
:::code language="fsharp" source="~/snippets/fsharp/System/Uri/HostComparison/source.fs" id="SnippetHostComparison":::
1631-
:::code language="vb" source="~/snippets/visualbasic/System/Uri/HostComparison/source.vb" id="SnippetHostComparison":::
1632-
16331624
]]></format>
16341625
</remarks>
16351626
<exception cref="T:System.InvalidOperationException">This instance represents a relative URI, and this property is valid only for absolute URIs.</exception>
@@ -2631,17 +2622,16 @@ The following examples show a URI and the results of calling <xref:System.Uri.Ge
26312622
- For **IPv6 addresses**: Returns the address with square brackets (for example, `[::1]` or `[fe80::1]`) but doesn't include the zone ID (scope) even if one was specified in the original URI.
26322623
- For **IPv4 addresses**: Returns the dotted-decimal notation (for example, `192.168.1.1`).
26332624
2634-
## Comparison with other Host properties
2625+
## Comparison with IdnHost
26352626
2636-
The <xref:System.Uri> class provides three host properties that serve different purposes:
2627+
The <xref:System.Uri> class provides two main host properties:
26372628
2638-
- <xref:System.Uri.Host%2A>: Returns the escaped input as provided in the URI. For IPv6, includes brackets but not the zone ID.
2639-
- <xref:System.Uri.IdnHost%2A>: Returns a DNS-safe representation. Non-ASCII hostnames are punycode encoded. For IPv6, doesn't include brackets but does include the zone ID.
2640-
- <xref:System.Uri.DnsSafeHost%2A>: Legacy property that behaves similarly to <xref:System.Uri.IdnHost%2A> but depends on app configuration. Use <xref:System.Uri.IdnHost%2A> instead.
2629+
- <xref:System.Uri.Host%2A>: Returns the host as it appears in the URI. For IPv6, includes brackets but not the zone ID.
2630+
- <xref:System.Uri.IdnHost%2A>: Returns a format suitable for DNS resolution. For valid international domain names, applies punycode encoding. For IPv6, doesn't include brackets but does include the zone ID.
26412631
26422632
Which property to use depends on your scenario:
26432633
- Use <xref:System.Uri.Host%2A> when you need the original host string as it appears in the URI (for display or comparison).
2644-
- Use <xref:System.Uri.IdnHost%2A> when you need a DNS-safe format (for DNS resolution or APIs that require punycode).
2634+
- Use <xref:System.Uri.IdnHost%2A> when you need a format suitable for DNS resolution or network APIs.
26452635
26462636
## Examples
26472637
The following example writes the host name (`www.contoso.com`) of the server to the console.
@@ -2650,11 +2640,9 @@ The following examples show a URI and the results of calling <xref:System.Uri.Ge
26502640
:::code language="fsharp" source="~/snippets/fsharp/System/Uri/Host/source.fs" id="Snippet1":::
26512641
:::code language="vb" source="~/snippets/visualbasic/System/Uri/Host/source.vb" id="Snippet1":::
26522642
2653-
The following example demonstrates the differences between <xref:System.Uri.Host%2A>, <xref:System.Uri.IdnHost%2A>, and <xref:System.Uri.DnsSafeHost%2A> for various URI types:
2643+
The following example demonstrates the differences between <xref:System.Uri.Host%2A> and <xref:System.Uri.IdnHost%2A> for various URI types:
26542644
26552645
:::code language="csharp" source="~/snippets/csharp/System/Uri/HostComparison/source.cs" id="SnippetHostComparison":::
2656-
:::code language="fsharp" source="~/snippets/fsharp/System/Uri/HostComparison/source.fs" id="SnippetHostComparison":::
2657-
:::code language="vb" source="~/snippets/visualbasic/System/Uri/HostComparison/source.vb" id="SnippetHostComparison":::
26582646
26592647
]]></format>
26602648
</remarks>
@@ -2764,21 +2752,20 @@ The following examples show a URI and the results of calling <xref:System.Uri.Ge
27642752
27652753
The behavior of this property depends on the host type:
27662754
2767-
- For **regular DNS hostnames**: Non-ASCII characters are punycode encoded (for example, `münchen.de` becomes `xn--mnchen-3ya.de`).
2755+
- For **regular DNS hostnames**: For valid international domain names, non-ASCII characters are punycode encoded (for example, `münchen.de` becomes `xn--mnchen-3ya.de`). Invalid or malformed hostnames might return non-ASCII values.
27682756
- For **IPv6 addresses**: Returns the address without square brackets but includes the zone ID (scope) if one was specified (for example, `::1` or `fe80::1%18`).
27692757
- For **IPv4 addresses**: Returns the dotted-decimal notation (for example, `192.168.1.1`).
27702758
2771-
## Comparison with other Host properties
2759+
## Comparison with Host
27722760
2773-
The <xref:System.Uri> class provides three host properties that serve different purposes:
2761+
The <xref:System.Uri> class provides two main host properties:
27742762
2775-
- <xref:System.Uri.Host%2A>: Returns the escaped input as provided in the URI. For IPv6, includes brackets but not the zone ID.
2776-
- <xref:System.Uri.IdnHost%2A>: Returns a DNS-safe representation. Non-ASCII hostnames are punycode encoded. For IPv6, doesn't include brackets but does include the zone ID.
2777-
- <xref:System.Uri.DnsSafeHost%2A>: Legacy property that behaves similarly to <xref:System.Uri.IdnHost%2A> but depends on app configuration. Use <xref:System.Uri.IdnHost%2A> instead.
2763+
- <xref:System.Uri.Host%2A>: Returns the host as it appears in the URI. For IPv6, includes brackets but not the zone ID.
2764+
- <xref:System.Uri.IdnHost%2A>: Returns a format suitable for DNS resolution. For valid international domain names, applies punycode encoding. For IPv6, doesn't include brackets but does include the zone ID.
27782765
27792766
Which property to use depends on your scenario:
27802767
- Use <xref:System.Uri.Host%2A> when you need the original host string as it appears in the URI (for display or comparison).
2781-
- Use <xref:System.Uri.IdnHost%2A> when you need a DNS-safe format (for DNS resolution or APIs that require punycode).
2768+
- Use <xref:System.Uri.IdnHost%2A> when you need a format suitable for DNS resolution or network APIs.
27822769
27832770
The deprecated <xref:System.Uri.DnsSafeHost%2A> property is dependent on *app.config* settings, which can't be changed by Windows Store applications. <xref:System.Uri.IdnHost%2A> is provided as the preferred alternative to using <xref:System.Uri.DnsSafeHost%2A> because <xref:System.Uri.IdnHost%2A> is guaranteed to always be DNS safe, no matter what the current *app.config* settings might be.
27842771
@@ -2788,11 +2775,9 @@ The following examples show a URI and the results of calling <xref:System.Uri.Ge
27882775
27892776
## Examples
27902777
2791-
The following example demonstrates the differences between <xref:System.Uri.Host%2A>, <xref:System.Uri.IdnHost%2A>, and <xref:System.Uri.DnsSafeHost%2A> for various URI types:
2778+
The following example demonstrates the differences between <xref:System.Uri.Host%2A> and <xref:System.Uri.IdnHost%2A> for various URI types:
27922779
27932780
:::code language="csharp" source="~/snippets/csharp/System/Uri/HostComparison/source.cs" id="SnippetHostComparison":::
2794-
:::code language="fsharp" source="~/snippets/fsharp/System/Uri/HostComparison/source.fs" id="SnippetHostComparison":::
2795-
:::code language="vb" source="~/snippets/visualbasic/System/Uri/HostComparison/source.vb" id="SnippetHostComparison":::
27962781
27972782
]]></format>
27982783
</remarks>

0 commit comments

Comments
 (0)