Getting domains list for node programmatically in Umbraco CMS

Once you define hostnames for a Content node in Umbraco CMS in the back office -  it's easy to get the list in C# within a few lines of code.

Cultures and hostnames for Umbraco node

To do so you should use the domain service (IDomainService) and grab the domain service instance.

private readonly IDomainService _domainService;

You can get service instance using static service locator as follows:

_domainService = Current.Factory.GetInstance<IDomainService>();

The domain service has a very easy-to-use method named GetAssignedDomains that returns a list of domains for a given node id.

var domains = _domainService.GetAssignedDomains(1501, includeWildcards: true);

Example output

Domains list for umbraco node

Domains list for umbraco node - immediate window

Leave a Comment