Skip to content

Commit 946ce15

Browse files
authored
Restore HostNameType/IdnHost members, revert Linq and vbproj, minimal Uri.xml refinements
1 parent 67108dd commit 946ce15

4 files changed

Lines changed: 141 additions & 80 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
23
<PropertyGroup>
34
<OutputType>Exe</OutputType>
45
<TargetFramework>net6.0</TargetFramework>
56
</PropertyGroup>
7+
68
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net48</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Reference Include="System.Data.Linq" />
10+
</ItemGroup>
11+
12+
</Project>

xml/System/Uri.xml

Lines changed: 119 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,57 +1648,9 @@ For `uriString`, an IPv6 address in string form must be enclosed within brackets
16481648
## Remarks
16491649
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.
16501650
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.
16521652
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:
1667-
1668-
`\<section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />`
1669-
1670-
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.
17021654
17031655
## Examples
17041656
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://
17071659
:::code language="fsharp" source="~/snippets/fsharp/System/Uri/.ctor/nclurienhancements.fs" id="Snippet4":::
17081660
:::code language="vb" source="~/snippets/visualbasic/System/Uri/.ctor/nclurienhancements.vb" id="Snippet4":::
17091661
1710-
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.
17111663
17121664
]]></format>
17131665
</remarks>
@@ -2686,24 +2638,15 @@ The following examples show a URI and the results of calling <xref:System.Uri.Ge
26862638
<format type="text/markdown"><![CDATA[
26872639
26882640
## 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.
26902642
2691-
The behavior of this property depends on the host type:
2643+
The value returned by this property depends on the host type:
26922644
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.
26952647
- For **IPv4 addresses**: Returns the dotted-decimal notation (for example, `192.168.1.1`).
26962648
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).
27072650
27082651
## Examples
27092652
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
27122655
:::code language="fsharp" source="~/snippets/fsharp/System/Uri/Host/source.fs" id="Snippet1":::
27132656
:::code language="vb" source="~/snippets/visualbasic/System/Uri/Host/source.vb" id="Snippet1":::
27142657
2715-
- 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:
2659+
2660+
:::code language="csharp" source="~/snippets/csharp/System/Uri/HostComparison/source.cs" id="SnippetHostComparison":::
2661+
2662+
]]></format>
2663+
</remarks>
2664+
<exception cref="T:System.InvalidOperationException">This instance represents a relative URI, and this property is valid only for absolute URIs.</exception>
2665+
</Docs>
2666+
</Member>
2667+
<Member MemberName="HostNameType">
2668+
<MemberSignature Language="C#" Value="public UriHostNameType HostNameType { get; }" />
2669+
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.UriHostNameType HostNameType" />
2670+
<MemberSignature Language="DocId" Value="P:System.Uri.HostNameType" />
2671+
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property HostNameType As UriHostNameType" />
2672+
<MemberSignature Language="F#" Value="member this.HostNameType : UriHostNameType" Usage="System.Uri.HostNameType" />
2673+
<MemberSignature Language="C++ CLI" Value="public:&#xA; property UriHostNameType HostNameType { UriHostNameType get(); };" />
2674+
<MemberType>Property</MemberType>
2675+
<AssemblyInfo>
2676+
<AssemblyName>System.Runtime</AssemblyName>
2677+
<AssemblyVersion>4.1.0.0</AssemblyVersion>
2678+
<AssemblyVersion>4.2.0.0</AssemblyVersion>
2679+
<AssemblyVersion>4.2.1.0</AssemblyVersion>
2680+
<AssemblyVersion>4.2.2.0</AssemblyVersion>
2681+
<AssemblyVersion>5.0.0.0</AssemblyVersion>
2682+
<AssemblyVersion>6.0.0.0</AssemblyVersion>
2683+
<AssemblyVersion>7.0.0.0</AssemblyVersion>
2684+
<AssemblyVersion>8.0.0.0</AssemblyVersion>
2685+
<AssemblyVersion>9.0.0.0</AssemblyVersion>
2686+
<AssemblyVersion>10.0.0.0</AssemblyVersion>
2687+
<AssemblyVersion>11.0.0.0</AssemblyVersion>
2688+
</AssemblyInfo>
2689+
<AssemblyInfo>
2690+
<AssemblyName>System</AssemblyName>
2691+
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
2692+
<AssemblyVersion>2.0.0.0</AssemblyVersion>
2693+
<AssemblyVersion>2.0.5.0</AssemblyVersion>
2694+
<AssemblyVersion>4.0.0.0</AssemblyVersion>
2695+
</AssemblyInfo>
2696+
<AssemblyInfo>
2697+
<AssemblyName>netstandard</AssemblyName>
2698+
<AssemblyVersion>2.0.0.0</AssemblyVersion>
2699+
<AssemblyVersion>2.1.0.0</AssemblyVersion>
2700+
</AssemblyInfo>
2701+
<ReturnValue>
2702+
<ReturnType>System.UriHostNameType</ReturnType>
2703+
</ReturnValue>
2704+
<Docs>
2705+
<summary>Gets the type of the host name specified in the URI.</summary>
2706+
<value>A member of the <see cref="T:System.UriHostNameType" /> enumeration.</value>
2707+
<remarks>
2708+
<format type="text/markdown"><![CDATA[
27182709
2719-
## Comparison with Host
2710+
## Examples
2711+
The following example creates a <xref:System.Uri> instance and writes the <xref:System.Uri.HostNameType*> to the console.
27202712
2721-
The <xref:System.Uri> class provides two main host properties:
2713+
:::code language="csharp" source="~/snippets/csharp/System/Uri/CheckSchemeName/uriexamples.cs" id="Snippet9":::
2714+
:::code language="fsharp" source="~/snippets/fsharp/System/Uri/CheckSchemeName/uriexamples.fs" id="Snippet9":::
2715+
:::code language="vb" source="~/snippets/visualbasic/System/Uri/CheckSchemeName/uriexamples.vb" id="Snippet9":::
27222716
2723-
- <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+
<exception cref="T:System.InvalidOperationException">This instance represents a relative URI, and this property is valid only for absolute URIs.</exception>
2720+
</Docs>
2721+
</Member>
2722+
<Member MemberName="IdnHost">
2723+
<MemberSignature Language="C#" Value="public string IdnHost { get; }" />
2724+
<MemberSignature Language="ILAsm" Value=".property instance string IdnHost" />
2725+
<MemberSignature Language="DocId" Value="P:System.Uri.IdnHost" />
2726+
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property IdnHost As String" />
2727+
<MemberSignature Language="F#" Value="member this.IdnHost : string" Usage="System.Uri.IdnHost" />
2728+
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::String ^ IdnHost { System::String ^ get(); };" />
2729+
<MemberType>Property</MemberType>
2730+
<AssemblyInfo>
2731+
<AssemblyName>System.Runtime</AssemblyName>
2732+
<AssemblyVersion>4.1.0.0</AssemblyVersion>
2733+
<AssemblyVersion>4.2.0.0</AssemblyVersion>
2734+
<AssemblyVersion>4.2.1.0</AssemblyVersion>
2735+
<AssemblyVersion>4.2.2.0</AssemblyVersion>
2736+
<AssemblyVersion>5.0.0.0</AssemblyVersion>
2737+
<AssemblyVersion>6.0.0.0</AssemblyVersion>
2738+
<AssemblyVersion>7.0.0.0</AssemblyVersion>
2739+
<AssemblyVersion>8.0.0.0</AssemblyVersion>
2740+
<AssemblyVersion>9.0.0.0</AssemblyVersion>
2741+
<AssemblyVersion>10.0.0.0</AssemblyVersion>
2742+
<AssemblyVersion>11.0.0.0</AssemblyVersion>
2743+
</AssemblyInfo>
2744+
<AssemblyInfo>
2745+
<AssemblyName>System</AssemblyName>
2746+
<AssemblyVersion>2.0.5.0</AssemblyVersion>
2747+
<AssemblyVersion>4.0.0.0</AssemblyVersion>
2748+
</AssemblyInfo>
2749+
<AssemblyInfo>
2750+
<AssemblyName>netstandard</AssemblyName>
2751+
<AssemblyVersion>2.0.0.0</AssemblyVersion>
2752+
<AssemblyVersion>2.1.0.0</AssemblyVersion>
2753+
</AssemblyInfo>
2754+
<ReturnValue>
2755+
<ReturnType>System.String</ReturnType>
2756+
</ReturnValue>
2757+
<Docs>
2758+
<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+
<format type="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.
27252765
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:
27292767
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`).
27312771
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.
27332773
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.
27352775
27362776
## 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:
27392778
27402779
:::code language="csharp" source="~/snippets/csharp/System/Uri/HostComparison/source.cs" id="SnippetHostComparison":::
27412780

0 commit comments

Comments
 (0)