Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Joel 1 post 71 karma points
    1 week ago

    DefaultUrlProvider not running GetUrl() override on all requests; cached values being used


    We have an implementation of DefaultUrlProvider registered in our Umbraco 10.6.1 website. The problem we are facing is that the overridden GetUrl() method we have implemented only ever seems to get run when the application is started, or when any content is published. As a result, the previously overridden URL values are retrieved from the publishedValueFallback passed into the constructor, from when the application was last started or when any content was published.




        public OurUrlProvider(IOurUrlProviderService ourUrlParserService, IOptionsMonitor<global::Umbraco.Cms.Core.Configuration.Models.RequestHandlerSettings> requestSettings, ILogger<DefaultUrlProvider> logger, ISiteDomainMapper siteDomainMapper, IUmbracoContextAccessor umbracoContextAccessor, UriUtility uriUtility, global::Umbraco.Cms.Core.Services.ILocalizationService localizationService) : base(requestSettings, logger, siteDomainMapper, umbracoContextAccessor, uriUtility, localizationService)
            _ourUrlProviderService = ourUrlParserService;
        public override UrlInfo GetUrl(IPublishedContent content, UrlMode mode, string culture, Uri current)
            var baseUrl = base.GetUrl(content, mode, culture, current);
            if (content == null)
                return baseUrl;
            // logic to append IDs to URLs in links is done in this DI'd service
            var newUrl = _ourUrlProviderService.GetUrl(baseUrl);
            return newUrl;

    Some snippets from one of the generated models that is affected by this issue (constructor, and one of the properties where we would expect the links to be overridden by the DefaultUrlProvider middleware:

    Home.generated.cs (putting a breakpoint in this constructor and hitting the Home controller shows that the publishedValueFallback values are being used):

        public Home(IPublishedContent content, IPublishedValueFallback publishedValueFallback)
            : base(content, publishedValueFallback)
            _publishedValueFallback = publishedValueFallback;

    One of the properties that we would expect to be transformed by the DefaultUrlProvider (our OverrideableBlockListModel inherits from a collection of Umbraco's BlockListItem):

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "10.6.1+82eae48")]
    public virtual global::OurOrganisation.Umbraco.BlockLists.OverridableBlockListModel BlocksLinks 
       => this.Value<global::OurOrganisation.Umbraco.BlockLists.OverridableBlockListModel>(_publishedValueFallback, "blocksLinks");

    Is there any way to tell our models to not use the PublishedValueFallback? Or is there something missing in the setup of the DefaultUrlProvider middleware? Any help would be greatly appreciated!


Please Sign in or register to post replies

Write your reply to: