Im trying to implement a custom Url Builder with Sitecore 9.3.I can't seem to figure out how to patch it. I made a custom url builder that implements BaseUrlBuilder but when I try to patch it in I get:

Unable to cast object of type 'Transform.Foundation.ItemResolution.CustomItemUrlBuilder' to type 'Sitecore.Links.UrlBuilders.ItemUrlBuilder'.

Here is the current state of my patch file:

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <itemUrlBuilder type="MySolution.Foundation.ItemResolution.CustomItemUrlBuilder,MySolution" patch:instead="*[@type='Sitecore.Links.UrlBuilders.ItemUrlBuilder, Sitecore.Kernel']">
            <param type="Sitecore.Links.UrlBuilders.DefaultItemUrlBuilderOptions, Sitecore.Kernel" desc="defaultOptions">
                <alwaysIncludeServerUrl ref="links/urlBuilder/alwaysIncludeServerUrl"/>
                <languageEmbedding ref="links/urlBuilder/languageEmbedding"/>
                <languageLocation ref="links/urlBuilder/languageLocation"/>
                <lowercaseUrls ref="links/urlBuilder/lowercaseUrls"/>
                <encodeNames ref="links/urlBuilder/encodeNames"/>
                <useDisplayName ref="links/urlBuilder/useDisplayName"/>
  • 1
    Try inheriting from Sitecore.Links.UrlBuilders.ItemUrlBuilder and override the Build(item, options) method. BaseUrlBuilder doesn't appear to be registered in Services Config so this still does not appear to be using the IOC container.
    – jammykam
    Commented Jul 21, 2020 at 3:35
  • Can you add that as an answer? That was it. Commented Jul 21, 2020 at 17:25
  • Thanks, answer added, and updated - BuildUrl() would be probably a better method to override just for the custom link generation part.
    – jammykam
    Commented Jul 24, 2020 at 20:37

1 Answer 1


The update in Sitecore 9.3 adds the new itemUrlBuilder configuration to control how item and media URLs are built. Unfortunately, this in not wired into the IoC container (unlike the LinkManager itself for example). The Sitecore documentation states:

The default Sitecore implementation of the BaseLinkManager class uses the Sitecore.Links.LinkProvider class. The LinkProvider class uses the ItemUrlBuilder class to generate item URLs.

If you take a look at the default implementation of the LinkProvider class you will see that the Initialize method uses the Sitecore Config Factory to create the itemUrlBuilder object, which is of type ItemUrlBuilder (and not of type BaseUrlBuilder)

Since the sitecore/links/itemUrlBuilder is indirectly called via the LinkProvider, you should instead inherit from Sitecore.Links.UrlBuilders.ItemUrlBuilder and override the BuildUrl(item, options) method.

public class CustomItemUrlBuilder : Sitecore.Links.UrlBuilders.ItemUrlBuilder
    public override string BuildUrl(Item item, ItemUrlBuilderOptions options)
        if (true) {
            // my custom url builder code
        } else {
            return base.BuildUrl(item, options);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.