I am creating a scheduled job in Episerver to generate a Google Site Map and I need to get the sites URL (domain) to append to the URLs. I have 3 environments, UAT, Pre Prod and Live and I need to test on all 3 so it would be nice to dynamically get the domain.
You can use the ISiteDefinitionRespository to get access to all of the defined hosts.
protected SiteDefinition GetSiteDefinitionFromSiteUri(Uri sitemapSiteUri)
.FirstOrDefault(siteDef => siteDef.SiteUrl == sitemapSiteUri || siteDef.Hosts.Any(hostDef => hostDef.Name.Equals(sitemapSiteUri.Host, StringComparison.InvariantCultureIgnoreCase)));
If you're not doing anything really custom, have you looked at using Geta.SEO.Sitemaps package? It generates SEO sitemaps on a schedule for configured hosts and works well in multi-site scenarios. Could save you some time.