August 29th, 2024

How is the Windows.Foundation.Uri.Domain property different from Host?

The Windows Runtime class Windows.Foundation.Uri has two string properties: Host and Domain. What’s the difference?

Let’s start with Host. This is the “host” as defined in RFC 3986 which defines the syntax for URIs.

Okay, that was easy. What about Domain?

The Domain is an attempt to identify the part of the Host that was registered with a top-level domain (TLD) registrar.

Host Domain
example.com example.com
mail.example.com example.com
www.bbc.co.uk bbc.co.uk
bbc.co.uk bbc.co.uk

The code for the Domain property applies a bunch of rules to determine how many levels of the fully-qualified domain name should be used to determine the “domain”.

The problem is that the authority for these rules is “whoever runs the TLD”. We see that different TLDs have different policies: The .com TLD allows organizations to register second-level domains, whereas the .uk TLD registers organizations as third-level domains, under .co.uk. There is no standard for how each TLD assigns its domains; each TLD can choose whatever pattern it likes.

What’s more, there’s no requirement that a TLD stick to the pattern it chose originally, or even have a pattern at all. For example, the .br TLD (waves hello in Brazilian Portuguese) originally registered organizations under the third level, so you got names like contoso.com.br, but it then decided to allow organizations (primarily universities) to register as second-level domains. This means that if you are given a domain under .br, you have to look at the second-level domain and see if it’s on a list of known reserved second-level domains such as com.br for commercial organizations or slg.br for (checks notes) sociologists. If so, then the third-level domain is the organizational domain; otherwise, you have an organization that was granted a second-level domain.

There are over 100 defined reserved second-level domains under .br, and I suspect that the list has grown even longer while I was sleeping. It’s practically impossible to keep up with all of these changes in TLD policy around the world, so what you get from the Domain property is a best-guess at the organizational domain. And at least for the .br TLD, it’s definitely not completely up to date. For example, it thinks that the organizational domain for mail.contoso.tec.br is tec.br instead of contoso.tec.br.

So what is Domain good for?

I’m not sure. It’s trying its best, but the world is too complicated.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

6 comments

Discussion is closed. Login to edit/delete existing comments.

  • Mateo Plavec · Edited

    It’s practically impossible to keep up with all of these changes in TLD policy around the world

    The Public Suffix List is meant to track such things. I wonder if Domain uses that list (albeit an outdated version).

  • Leonardo Brondani Schenkel

    For the same reason the Public Suffix List was created, correct? Couldn’t it maybe retrofitted to use a snapshot of the PSL under the scenes?

  • Kevin Norris

    ccTLDs are basically a mess. Unfortunately, it's a case of the technology reflecting messy reality, rather than something you can "just fix." Governments want to administer their own domains, for various administrative and political reasons that range from "we don't want our citizens getting scammed by fake government websites" to "if the US government can have .gov and .mil, then we should be allowed to have our own official domains too." There was probably, at...

    Read more
  • knewt

    So my initial thought would be that ‘Domain’ is intended to match the web ‘same site’ definition, which uses the Public Suffix List (PSL).

    But if that was the case, I would also expect it to get regularly synced with the official list. Which most obviously isn’t the case here, since tec.br was added as a new official SLD in July-2020 !!

  • deadcream · Edited

    There is a Mozilla’s Public Suffix List project specifically for this purpose. On Linux it is typically used via libpsl C library, with the list itself updated separately system-wide, so that applications won’t need to bundle it.

  • Piotr Siódmak

    A better question would be “why was Domain created?”
    I’m guessing code for the Windows Runtime is not added just because a dev felt like it.