Copied to clipboard

Flag this post as spam?

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

  • Christian John Schmidt 7 posts 110 karma points
    Apr 08, 2019 @ 11:49
    Christian John Schmidt

    Url with domain in Umbraco 8

    In order to get an url with domain in V7 you could do like this:

                   UmbracoHelper uh = new UmbracoHelper(UmbracoContext.Current);
                    IPublishedContent content = uh.TypedContent(node.Id);
                    string url =content.UrlWithDomain()

    However the .UrlWithDomain() method has been removed in V8. Is there a similar way to do this? The code needs to work in an IComponent

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 08, 2019 @ 17:45
    Corné Strijkert

    Maybe you are searching for this method?

  • Marc Goodson 2149 posts 14354 karma points MVP 9x c-trib
    Apr 08, 2019 @ 18:43
    Marc Goodson

    Hi Christian

    Corné is correct UrlAbsolute() is the new name for UrlWithDomain()...

    inside a Component, you'll need to inject IUmbracoContextFactory, and use EnsureUmbracoContext() to be able to pull back the IPublishedContent item you are after...

    ... something like this:

    using System;
    using System.Collections.Generic;
    using Umbraco.Core.Composing;
    using Umbraco.Core.Models.PublishedContent;
    using Umbraco.Web;
    namespace Umbraco8.Components
        public class ExampleComposer : ComponentComposer<ExampleComponent>
        public class ExampleComponent : IComponent
            private readonly IUmbracoContextFactory _umbracoContextFactory;
    public ExampleComponent(IUmbracoContextFactory umbracoContextFactory)
                _umbracoContextFactory = umbracoContextFactory;
            public void Initialize()
               using (var umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext())
                    var contentCache = umbracoContextReference.UmbracoContext.ContentCache;
                    //get IPublishedContent
                    IPublishedContent particularItem = contentCache.GetById(node.Id);
                    string url = particularItem.UrlAbsolute();
            public void Terminate()
                throw new NotImplementedException();
  • Christian John Schmidt 7 posts 110 karma points
    Apr 09, 2019 @ 05:27
    Christian John Schmidt

    This is exactly the solution i was already using! However for me the UrlAbsolute method only returned the relative path.

    I found out that the reason for this, was that I was working locally and therefore did not set the domain in culture and hostnames

  • Chris Kim 48 posts 254 karma points c-trib
    Jul 11, 2019 @ 08:09
    Chris Kim

    Note that as of version 8.1 .UrlAbsolute() has been removed and I found one can now use .Url(mode: UrlMode.Absolute).

    I could not find any reference to this in the release notes / fixed issues list, so I had to look at the history for PublishedContentExtensions.cs and found this commit which removed it: further down I noticed this change to UmbracoContext.cs which led me to the solution: [Obsolete("Use the Url() method with UrlMode.Absolute.")]

  • Luke Hook 45 posts 175 karma points c-trib
    Jul 11, 2019 @ 09:05
    Luke Hook

    For reference, after searching myself I did find this within the release notes but bundled under IPublishedContent refurb

    Refurbish IPublishedContent

    Here is an extracted summary of explicit changes from Stephan.

    The following IPublishedContent members change:

    Name: content.Name is gone, content.GetCulture(...).Name is gone, the proper way to get a name is content.Name(string culture = null)

    UrlSegment: content.UrlSegment is gone, content.GetCulture(...).UrlSegment is gone, the proper way to get a Url segment is content.UrlSegment(string culture = null)

    ItemType: content.ItemType is gone, the proper way to get the item type is content.ContentType.ItemType

    Culture: content.Cultures now returns a collection of string representing the available cultures, and content.GetCulture(...) is gone, the proper way to get the culture date is content.CultureDate(string culture = null)

    Parent: content.Parent is gone, the proper way to get the parent is content.Parent()

    Children: content.Children is gone, the proper way to get the children is content.Children(string culture = null) and it always filters children according to culture

    Url: content.Url, .GetUrl(...), .Url(), .UrlAbsolute() are all gone, the proper way to get the Url is content.Url(string culture = null, UrlMode mode = UrlMode.Auto) which produces a relative-or-absolute Url depending on what's "best", but can be forced to produce absolute Urls with UrlMode.Absolute

    (Apologies that's not very easy to read)

    Definitely think this needed to be made more obvious within the release notes, especially if the documentation isn't updated yet.

  • Chris Kim 48 posts 254 karma points c-trib
    Jul 11, 2019 @ 11:28
    Chris Kim

    I see, thanks for referring to that ticket. The details are buried in the comments, so I really feel like this should be detailed a bit more in the version-specific upgrade guide.

  • wilmar 19 posts 129 karma points
    Jan 21, 2021 @ 11:33

    why is this so complicated how can i read IPublishedContent URL on umbraco 8 what extension are they taking about ? what extension are they taking about ?

  • Chris Kim 48 posts 254 karma points c-trib
    Jan 21, 2021 @ 20:06
    Chris Kim

    Instead of the property .Url you use the method .Url() (which has parameters for UrlMode and culture should you need them).

Please Sign in or register to post replies

Write your reply to: