The documentation at http://msdn.microsoft.com/en-us/library/system.urihostnametype.aspx and http://msdn.microsoft.com/en-us/library/system.uri.checkhostname.aspx is a bit unclear.
Uri.CheckHostName(string)
returns UriHostNameType.Dns
for a valid DNS hostname, and it returns UriHostNameType.Unknown
when the string contains invalid characters and so on. Under what conditions does this method ever return UriHostNameType.Basic
?
Now the .NET Core is open source we can know for sure.
Just like Mono, it never returns UriHostNameType.Basic
.
Link to source code
It occurred to me that I could just check the Mono source code to answer my question. Here is the CheckHostName
method from https://github.com/mono/mono/blob/master/mcs/class/System/System/Uri.cs:
public static UriHostNameType CheckHostName (string name)
{
if (name == null || name.Length == 0)
return UriHostNameType.Unknown;
if (IsIPv4Address (name))
return UriHostNameType.IPv4;
if (IsDomainAddress (name))
return UriHostNameType.Dns;
IPv6Address addr;
if (IPv6Address.TryParse (name, out addr))
return UriHostNameType.IPv6;
return UriHostNameType.Unknown;
}
It appears that UriHostNameType.Basic
isn't used at all. Maybe the Microsoft implementation can return this value?
UriHostNameType.Basic
is used by the UriBuilder
and Uri
, when there is a DNS host name where at least 1 of the domain labels begins with a "-" (dash) or an "_" (underscore). For example, "_caldavs._tcp.google.com" will return UriHostNameType.Basic
.
However, Uri.CheckHostName(string)
appears to never return this value. For the same DNS host name above it returns UriHostNameType.Unknown
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With