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

How can i get a reference to the start page from within a scheduled task?

Vote:
 

I have a scheduled task that requires a reference to the start page, but ContentReference.StartPage is null in this situation.

From what I have seen other people get round this by putting * in as host - but I am pretty sure the client is not going to go for that on prod and anyway it feels like a bodge (workaround for bad code).

What is the correct way to get a reference to the start page in this situation?

#178745
May 19, 2017 17:50
Vote:
 

Since a scheduled job is outside the Context, Episerver don't know WHICH start page you'd be referring to in case you'd have a multi site setup, and which language.

Check the SiteDefinitionRepository

var siteDefinitionRepository = ServiceLocator.Current.GetInstance<SiteDefinitionRepository>();
var siteDefinitions = siteDefinitionRepository.List().ToList();
foreach (var siteDefinition in siteDefinitions)
{
...
}

Check what you can do with the SiteDefinition here. For example siteDefinition.StartPage

http://world.episerver.com/documentation/class-library/?documentId=cms/10/D08CD219

#178751
May 19, 2017 22:01
Vote:
 

Thanks a lot Alf - thats excellent. :)

#178753
May 20, 2017 14:15
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.