AI OnAI Off
Hi,
Scheduled jobs don't really execute in the context of a specific site so I suspect SiteDefinition.Current might not work. I tend to use ISiteDefinitionRepository to get all site instances and just pick one (either a specific one or, if the specific site's not important, the first) like this:
var currentSite = SiteDefinition.Current;
if (currentSite == null || ContentReference.IsNullOrEmpty(currentSite.StartPage))
{
currentSite = ServiceLocator.Current.GetInstance<ISiteDefinitionRepository>().List().FirstOrDefault();
}
if (currentSite == null)
{
return "No sites defined";
}
Actually, looking at the comment on SiteDefinition.Current, you can ensure a site definition is always returned by setting a wildcard host mapping (*) in the site configuration in admin mode though it's still worthwhile handling the situation where a site definition can't be resolved.
Hi
how can we get the current site ID or site settings from the schedule job. I have tried with HttpContext.Current but it's giving null because jobs are not executed on a web request. I have to update the page/block by using the schedule job.
Thanks