We use hangfire on an Umbraco 13 site to rebuild azure search indexes.
We've had issues with the search index falling over if we manually trigger the task, but if it runs at it's scheduled time it works fine.
While debugging I noticed that the UmbracoContext has the wrong urls locally, it is defaulting to 'localhost' for the 'cleanUrl' even though we have a custom domain set in the 'Domain and Host Names' for the site.
I'm not sure if this is the cause, but now it is failing to get any content out (see the below)
var cref = _umbracoContextFactory.EnsureUmbracoContext();
using (var umbracoContext = cref.UmbracoContext)
{
if (umbracoContext.Content == null)
{
return response;
}
var homepage = umbracoContext.Content
.GetAtRoot(false)
.FirstOrDefault(c => c.ContentType.Alias ==
HomePage.ModelTypeAlias);
}
In this case 'homepage' is null
Does anyone have any idea why the context is using the wrong urls and if that could be the cause of homepage being null?
Umbraco Context in Hangfire Task
We use hangfire on an Umbraco 13 site to rebuild azure search indexes.
We've had issues with the search index falling over if we manually trigger the task, but if it runs at it's scheduled time it works fine.
While debugging I noticed that the UmbracoContext has the wrong urls locally, it is defaulting to 'localhost' for the 'cleanUrl' even though we have a custom domain set in the 'Domain and Host Names' for the site.
I'm not sure if this is the cause, but now it is failing to get any content out (see the below)
In this case 'homepage' is null
Does anyone have any idea why the context is using the wrong urls and if that could be the cause of homepage being null?
Update on this, I have found that when creating the ContextFactory, the HttpContext is null:
so it is defaulting to 'localhost' for the URLs.
have looked through the docs and other sites we've built that use hangfire and I can't see why this is the case.
Anyone have any suggestions?
is working on a reply...