Copied to clipboard

Flag this post as spam?

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


  • Jensen 4 posts 74 karma points
    Feb 18, 2023 @ 11:39
    Jensen
    0

    Getting domain for specific node in code

    hi, I have made a small umbraco 11 project, that I just made from sratch, with the starter template. I then added a small homepage, and gave it two domains with the same language

    enter image description here

    and I then made this small snippet to get the node, and the url for the node:

            var content = umbracoContextReference.UmbracoContext.Content;
            IPublishedContent? res = content.GetById(pageId);
            var url =res.Url();
    

    and this always gets the url which is the lastly added one (the bottom one)

    But I would like to be able to get the see both of the url's, which in my understanding both are mapped to the node. So that I can pick the one that is fitting.

    While googling, I found this question which uses:

    Domain.GetDomainsById(node.Id);
    

    but this did seem to be deprecated, and I also could'nt make the ApplicationContext solution work mentioned in the comments

    Is there something equivalent to GetDomainsById I can use, or some other way that I can get all domains for a given IPublishedContent?

    Best regards :)

    EDIT:

    If I change the culture/language to something another language like danish, then I am able to target the url with that specific culture like so:

    var url =res.Url("da");
    

    But when the domains have the same culture, this is not doable

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" button below.

    Continue discussion

Please Sign in or register to post replies