You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1648,57 +1648,9 @@ For `uriString`, an IPv6 address in string form must be enclosed within brackets
1648
1648
## Remarks
1649
1649
For IPv6 addresses, the brackets ([]) are removed and the <xref:System.Net.IPAddress.ScopeId> property is set, if one was specified when this instance was constructed.
1650
1650
1651
-
If you used an escaped string to construct this instance (for example, `"http://[fe80::200:39ff:fe36:1a2d%254]/temp/example.htm"`), then <xref:System.Uri.DnsSafeHost%2A> returns an escaped string. Unescape any escaped string returned from `DnsSafeHost` before using that string for DNS resolution (see the Example). If you used an invalid unescaped string to construct this instance (for example, "http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm"), then <xref:System.Uri.DnsSafeHost%2A> returns an unescaped string.
1651
+
<xref:System.Uri.DnsSafeHost%2A> is a legacy property whose behavior depends on configuration settings in .NET Framework apps. For new code, prefer <xref:System.Uri.IdnHost%2A>, which is configuration-independent and produces a value suitable for DNS resolution. See <xref:System.Uri.Host%2A> and <xref:System.Uri.IdnHost%2A> for guidance on choosing a host property.
1652
1652
1653
-
## Comparison with other Host properties
1654
-
1655
-
The <xref:System.Uri> class provides two main host properties:
1656
-
1657
-
- <xref:System.Uri.Host%2A>: Returns the host as it appears in the URI. For IPv6, includes brackets but not the zone ID.
1658
-
- <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.
1659
-
1660
-
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.
1661
-
1662
-
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> typically returns a value that's suitable for DNS resolution.
1663
-
1664
-
The <xref:System.Uri.DnsSafeHost%2A> property was extended in .NET Framework v3.5, 3.0 SP1, and 2.0 SP1 to provide International Resource Identifier (IRI) support based on RFC 3987. However, to ensure application compatibility with prior versions, you must specifically enable it in .NET Framework apps. To enable support for IRI, the following two changes are required:
1665
-
1666
-
1. Add the following line to the *machine.config* file under the .NET Framework 2.0 directory:
2. Specify whether you want Internationalized Domain Name (IDN) parsing applied to the domain name and whether IRI parsing rules should be applied. This can be done in the *machine.config* or in the *app.config* file. For example, add the following:
1671
-
1672
-
```xml
1673
-
<configuration>
1674
-
<uri>
1675
-
<idn enabled="All" />
1676
-
<iriParsing enabled="true" />
1677
-
</uri>
1678
-
</configuration>
1679
-
```
1680
-
1681
-
Enabling IDN converts all Unicode labels in a domain name to their Punycode equivalents. Punycode names contain only ASCII characters and always start with the xn-- prefix. The reason for this is to support existing DNS servers on the Internet, since most DNS servers only support ASCII characters (see RFC 3940).
1682
-
1683
-
Enabling IDN only affects the value of the <xref:System.Uri.DnsSafeHost%2A> property.
1684
-
1685
-
There are three possible values for IDN depending on the DNS servers that are used:
1686
-
1687
-
- idn enabled = All
1688
-
1689
-
This value will convert any Unicode domain names to their Punycode equivalents (IDN names).
1690
-
1691
-
- idn enabled = AllExceptIntranet
1692
-
1693
-
This value will convert all external Unicode domain names to use the Punycode equivalents (IDN names). In this case to handle international names on the local Intranet, the DNS servers that are used for the Intranet should support Unicode names.
1694
-
1695
-
- idn enabled = None
1696
-
1697
-
This value won't convert any Unicode domain names to use Punycode. This is the default value, which is consistent with the .NET Framework 2.0 behavior.
1698
-
1699
-
Enabling IRI parsing (iriParsing enabled = `true`) normalizes and checks characters according to the IRI rules in RFC 3987. The default value is `false` and normalizes and checks characters according to RFC 2396 and RFC 2732 (for IPv6 literals).
1700
-
1701
-
For more information on IRI support, see the Remarks section for the <xref:System.Uri> class.
1653
+
If you used an escaped string to construct this instance (for example, `"http://[fe80::200:39ff:fe36:1a2d%254]/temp/example.htm"`), then DnsSafeHost returns an escaped string. Unescape any escaped string returned from `DnsSafeHost` before using that string for DNS resolution (see the Example). If you used an invalid unescaped string to construct this instance (for example, "http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm"), then DnsSafeHost returns an unescaped string.
1702
1654
1703
1655
## Examples
1704
1656
The following example creates a <xref:System.Uri> instance from a string. It illustrates the difference between the value returned from <xref:System.Uri.Host*>, which returns the host name or address specified in the URI, and the value returned from <xref:System.Uri.DnsSafeHost*>, which returns an address that is safe to use in DNS resolution.
@@ -1707,7 +1659,7 @@ If you used an escaped string to construct this instance (for example, `"http://
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.
1662
+
As explained in Remarks, unescape the host name before resolving it. You can use the <xref:System.Uri.UnescapeDataString*> method to unescape the host name, and you can resolve it by calling the <xref:System.Net.Dns.GetHostEntry*> method.
1711
1663
1712
1664
]]></format>
1713
1665
</remarks>
@@ -2686,24 +2638,15 @@ The following examples show a URI and the results of calling <xref:System.Uri.Ge
2686
2638
<formattype="text/markdown"><![CDATA[
2687
2639
2688
2640
## Remarks
2689
-
Unlike the <xref:System.Uri.Authority%2A> property, this property value doesn't include the port number.
2641
+
Unlike the <xref:System.Uri.Authority> property, this property value does not include the port number.
2690
2642
2691
-
The behavior of this property depends on the host type:
2643
+
The value returned by this property depends on the host type:
2692
2644
2693
-
- For **regular DNS hostnames**: Returns the escaped input. Non-ASCII characters are returned as-is without punycode encoding.
2694
-
- 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.
2645
+
- For **DNS host names** (including international domain names): Returns the escaped input. Non-ASCII characters are returned as-is and aren't punycode encoded.
2646
+
- For **IPv6 addresses**: Returns the address enclosed in square brackets (for example, `[::1]`), but doesn't include the zone ID (scope) even if one was specified in the original URI.
2695
2647
- For **IPv4 addresses**: Returns the dotted-decimal notation (for example, `192.168.1.1`).
2696
2648
2697
-
## Comparison with IdnHost
2698
-
2699
-
The <xref:System.Uri> class provides two main host properties:
2700
-
2701
-
- <xref:System.Uri.Host%2A>: Returns the host as it appears in the URI. For IPv6, includes brackets but not the zone ID.
2702
-
- <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.
2703
-
2704
-
Which property to use depends on your scenario:
2705
-
- Use <xref:System.Uri.Host%2A> when you need the original host string as it appears in the URI (for display or comparison).
2706
-
- Use <xref:System.Uri.IdnHost%2A> when you need a format suitable for DNS resolution or network APIs.
2649
+
For DNS resolution or other lower-level networking scenarios, use <xref:System.Uri.IdnHost%2A> instead, which returns a punycode-encoded form for valid international domain names and includes the zone ID (without brackets) for IPv6 addresses. Use <xref:System.Uri.Host%2A> when you want the host as it appears in the URI (for example, for display or comparison).
2707
2650
2708
2651
## Examples
2709
2652
The following example writes the host name (`www.contoso.com`) of the server to the console.
@@ -2712,30 +2655,126 @@ The following examples show a URI and the results of calling <xref:System.Uri.Ge
- 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.
2716
-
- 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`).
2717
-
- For **IPv4 addresses**: Returns the dotted-decimal notation (for example, `192.168.1.1`).
2658
+
The following example shows how <xref:System.Uri.Host%2A> and <xref:System.Uri.IdnHost%2A> differ across DNS, IDN, IPv4, and IPv6 inputs:
<exceptioncref="T:System.InvalidOperationException">This instance represents a relative URI, and this property is valid only for absolute URIs.</exception>
- <xref:System.Uri.Host%2A>: Returns the host as it appears in the URI. For IPv6, includes brackets but not the zone ID.
2724
-
- <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.
2717
+
]]></format>
2718
+
</remarks>
2719
+
<exceptioncref="T:System.InvalidOperationException">This instance represents a relative URI, and this property is valid only for absolute URIs.</exception>
<summary>Gets the RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate. This string, after being unescaped if necessary, is safe to use for DNS resolution.</summary>
2759
+
<value>The hostname, formatted with Punycode according to the IDN standard.</value>
2760
+
<remarks>
2761
+
<formattype="text/markdown"><![CDATA[
2762
+
2763
+
## Remarks
2764
+
This property is provided for the use of lower-level networking protocols that require the domain name in Punycode form. If your code does not require that specific format, use <xref:System.Uri.Host*> for the hostname.
2725
2765
2726
-
Which property to use depends on your scenario:
2727
-
- Use <xref:System.Uri.Host%2A> when you need the original host string as it appears in the URI (for display or comparison).
2728
-
- Use <xref:System.Uri.IdnHost%2A> when you need a format suitable for DNS resolution or network APIs.
2766
+
The value returned by this property depends on the host type:
2729
2767
2730
-
The legacy <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 it doesn't depend on *app.config* settings, and it's designed to produce a host value that works for typical DNS resolution scenarios. Callers should still validate or normalize the returned value, especially for malformed hostnames or IPv6 addresses that include a zone ID.
2768
+
- For **DNS host names**: For valid international domain names, non-ASCII characters are punycode encoded (for example, `münchen.de` becomes `xn--mnchen-3ya.de`). Hostnames that aren't valid IDNs might be returned as-is and include non-ASCII characters.
2769
+
- For **IPv6 addresses**: Returns the address without the surrounding brackets, and includes the zone ID (scope) if one was specified (for example, `::1` or `fe80::1%18`).
2770
+
- For **IPv4 addresses**: Returns the dotted-decimal notation (for example, `192.168.1.1`).
2731
2771
2732
-
## Escaping behavior
2772
+
<xref:System.Uri.IdnHost%2A> is the preferred alternative to the legacy <xref:System.Uri.DnsSafeHost%2A> property, because its behavior doesn't depend on *app.config* settings and it's designed to produce a value suitable for DNS resolution. Note that for IPv6 results that include a zone ID, callers may still need to strip the zone ID before passing the value to APIs that don't accept it.
2733
2773
2734
-
If you used an escaped string to construct this instance (for example, `"http://[fe80::200:39ff:fe36:1a2d%254]/temp/example.htm"`), then <xref:System.Uri.IdnHost%2A> returns an escaped string. You should unescape any escaped string returned from <xref:System.Uri.IdnHost%2A> before using that string for DNS resolution. Be aware that if you used an invalid unescaped string to construct this instance (for example, "http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm"), then <xref:System.Uri.IdnHost%2A> returns an unescaped string.
2774
+
If you used an escaped string to construct this instance (for example, `"http://[fe80::200:39ff:fe36:1a2d%254]/temp/example.htm"`), then IdnHost returns an escaped string. You should unescape any escaped string returned from IdnHost before using that string for DNS resolution. Be aware that if you used an invalid unescaped string to construct this instance (for example, "http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm"), then IdnHost returns an unescaped string.
2735
2775
2736
2776
## Examples
2737
-
2738
-
The following example demonstrates the differences between <xref:System.Uri.Host%2A> and <xref:System.Uri.IdnHost%2A> for various URI types:
2777
+
The following example shows how <xref:System.Uri.Host%2A> and <xref:System.Uri.IdnHost%2A> differ across DNS, IDN, IPv4, and IPv6 inputs:
0 commit comments