Copied to clipboard

Flag this post as spam?

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


  • Tom Steer 161 posts 596 karma points
    Aug 05, 2015 @ 08:47
    Tom Steer
    0

    UrlAbsolute/UrlWithDomain Issue

    Hey!

    I'm currently developing a site where I'm using custom routes and virtual content, the virtual content model inherits from PublishedContentModel in which I override the URL property to give my custom route rather than the wrapped contents URL. However when setting the canonical URL meta tag I use the UrlWithDomain() extension but this doesn't seem to use the overridden URL property to base it off. Is this by design or a bug? If by design is there some other method I can use to get this to work by any chance?

    Cheers,

    Tom

  • Hywel Rees 56 posts 224 karma points
    Aug 05, 2015 @ 12:38
    Hywel Rees
    100

    Hi Tom,

    UrlWithDomain is an extension method of IPublishedContent rather than PublishedContentModel, so will use the original absolute URl instead of your modified one.

    UrlWithDomain ultimately does this: return UmbracoContext.Current.UrlProvider.GetUrl(content.Id, true); So a 'fun' way might be to write and inject your own UrlProvider.

    A simpler way would be to create a new extension method which observes your url mapping.

  • Hywel Rees 56 posts 224 karma points
    Aug 05, 2015 @ 12:41
    Hywel Rees
    1
  • Hywel Rees 56 posts 224 karma points
    Aug 05, 2015 @ 13:11
    Hywel Rees
    0

    Also, you will need to register your IUrlProvider implementation, by implementing IApplicationEventHandler.

    In my case, I still want the DefaultUrlProvider, so In my OnApplicationStarting method, I would add

    UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, CustomUrlProvider>();
    

    Where CustomUrlProvider is my implementation of IUrlProvider.

    :)

  • Tom Steer 161 posts 596 karma points
    Aug 05, 2015 @ 14:28
    Tom Steer
    0

    Thanks Hywel makes sense now :)

Please Sign in or register to post replies

Write your reply to:

Draft