I'm trying to add Hangfire to my application. Every night, some tasks need to be performed. For that, I need access to the umbraco content. As tasks in Hangfire do not have an HttpContext, I use the UmbracoContextFactory:
public class TestService : BaseService
{
private readonly IUmbracoContextFactory _umbracoContextFactory;
public TestService(
CustomDbContext db,
IUmbracoContextFactory umbracoContextFactory
) : base(db)
{
_umbracoContextFactory = umbracoContextFactory;
}
public string Test()
{
using var ucr = _umbracoContextFactory.EnsureUmbracoContext();
var root = ucr.UmbracoContext.Content.GetAtRoot().FirstOrDefault();
return "";
}
}
However, root is always null if this is called by Hangfire. If I call this from a controller, I do get the root.
What is the correct/best way to get the root content node?
EnsureUmbracoContext gives no content
Hi all,
I'm trying to add Hangfire to my application. Every night, some tasks need to be performed. For that, I need access to the umbraco content. As tasks in Hangfire do not have an HttpContext, I use the UmbracoContextFactory:
However, root is always null if this is called by Hangfire. If I call this from a controller, I do get the root.
What is the correct/best way to get the root content node?
Cheers, Yannic
I just use IContentService in my hangfire job
is working on a reply...