Gets an unescaped host name that is safe to use for DNS resolution.
Assembly: System (in System.dll)
This instance represents a relative URI, and this property is valid only for absolute URIs.
For IPv6 addresses, the brackets () are removed and the ScopeId property is set, if one was specified when this instance was constructed.
Theproperty has been extended in .NET Framework v3.5, 3.0 SP1, and 2.0 SP1 to provide International Resource Identifier (IRI) support based on RFC 3987. Current users will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. This ensures application compatibility with prior versions of the .NET Framework.
To enable support for IRI, the following two changes are required:
Add the following line to the machine.config file under the .NET Framework 2.0 directory
<section name="uri" type="System.Configuration.UriSection, System, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
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:
<configuration> <uri> <idn enabled="All" /> <iriParsing enabled="true" /> </uri> </configuration>
Enabling IDN will convert 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).
Enabling IDN only affects the value of theproperty.
There are three possible values for IDN depending on the DNS servers that are used:
idn enabled = All
This value will convert any Unicode domain names to their Punycode equivalents (IDN names).
idn enabled = AllExceptIntranet
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.
idn enabled = None
This value will not convert any Unicode domain names to use Punycode. This is the default value which is consistent with the .NET Framework 2.0 behaviour.
Enabling IRI parsing (iriParsing enabled = true) will do normalization and character checking according to the latest IRI rules in RFC 3987. The default value is false and will do normalization and character checking according to RFC 2396 and RFC 2732 (for IPv6 literals).
For more information on IRI support, see the Remarks section for the Uri class.
The following example creates a Uri instance from a string. It illustrates the difference between the value returned from Host, which returns the host name or address specified in the URI, and the value returned from , which returns an address that is safe to use in DNS resolution.
// Create new Uri using a string address. Uri address = new Uri("http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm"); // Make the address DNS safe. // The following outputs "[fe80::200:39ff:fe36:1a2d]". Console.WriteLine(address.Host); // The following outputs "fe80::200:39ff:fe36:1a2d%4". Console.WriteLine(address.DnsSafeHost);
Available since 8
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1