Host vs DnsSafeHost

Apply DnsSafeHost to the URL if you intend to send the resulting host name to a DNS server on your own. DNS was originally an ASCII-only protocol (and a subset of ASCII at that). Present day URL’s allow character sequences in the host portion of a URL that cannot be sent directly to a DNS server. Examples are:

  • bracket-enclosed IPv6 addresses. DnsSafeHost drops the brackets.

  • Non-ASCII, non-English domain names. DnsSafeHost (optionally) uses RFC 3987 IRI to normalize the characters, and converts non-ASCII character to IDN, Punycode encoding.

  • Who knows what URLs will allow in the future? The application may well outlive our assumptions of what’s okay in a URL. DnsSafeHost adds a degree of resilience there.

If you need to display the host name to the user, use the Host property instead.

Leave a Comment