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

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 :slight_smile:

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 is a companion discussion topic for the original entry at https://our.umbraco.com/forum/111250-getting-domain-for-specific-node-in-code