November Happy Hour will be moved to Thursday December 5th.

Scheduled Job - get URL of site from settings

Vote:
 

Hi,

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.

Jon

#195747
Aug 07, 2018 10:51
Vote:
 

HttpContext.Current.Request.Url.Host

or

SiteDefinition.Current.SiteUrl.Host

#195770
Aug 07, 2018 14:28
Vote:
 

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

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



#195787
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.