Try our conversational search powered by Generative AI!

Scheduled Job - get URL of site from settings



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.


Aug 07, 2018 10:51




Aug 07, 2018 14:28

You can use the ISiteDefinitionRespository to get access to all of the defined hosts. 

 protected SiteDefinition GetSiteDefinitionFromSiteUri(Uri sitemapSiteUri)
            return this.SiteDefinitionRepository
                .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.

Aug 07, 2018 16:33
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.