Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alex Bromilow 2 posts 72 karma points
    23 days ago
    Alex Bromilow
    0

    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)

     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?

  • Alex Bromilow 2 posts 72 karma points
    23 days ago
    Alex Bromilow
    0

    Update on this, I have found that when creating the ContextFactory, the HttpContext is null:

    enter image description here

    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?

Please Sign in or register to post replies

Write your reply to:

Draft