Search code examples
urluriuribuilder

Why does .NET have a UriBuilder as opposed to a UrlBuilder?


OK, so having digested such excellent answers as this one difference between URLs and URIs, I think I now understand the distinction between the two.

What I now don't understand is why the .NET Framework has a UriBuilder class, which - as far as I can tell - only works on URIs which are resource locators and should therefore properly be called a UrlBuilder.

Can someone give me an example of UriBuilder being used to build a URI which is not a resource locator? Or some rationale for this decision in the design of the .NET framework?


Solution

  • When you think about it, a UriBuilder is more powerful and broader than a URL Builder. Since every URL is a URI, a UriBuilder is inherently a URL Builder.

    So basically the question is when could you use a UriBuilder for a non-URL URI. Well, I guess the best example would be for a URN (since URLs and URNs are basically locators and names -- the two classifications of URIs). A URN could be used, for example, to build a uuid (i.e. urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66) or an ISBN (i.e. ISBN 0-486-27557-4). These URNs don't contain location information that points to a resource like URLs do, they just contain names or ids. A UriBuilder would be able to build not just URLs (which point to a resource), but it would also be able to build URNs. If you look at the Uri.Scheme property, you will see uuid in the list of possible schemes for a Uri.

    Also, .NET does technically have a UrlBuilder class.