I need to create a list of 3 latest news items as a HTML in a background job to send them out as a newsletter.
I need absolute URLs to those news. If I call Umbracos built in method Url() like that:
latestNewsItem.Url("en", UrlMode.Absolute)
I get absolute URL with localhost domain instead of the correct one.
What I’m doing wrong?
I guess that when you usually create Url you have a domain in the request so the Url method takes it from there, but how can I utilise this method in Hangfire background job?
I debugged the UrlProvider.GetUrl and I see that the culture is specified in variationContextAccessor, but umbracoContext doesn’t have the correct url:
I have an UmbracoApplicationUrl appsettings option set up, but also this one will not help me, because we have different domain for Publisher node than Subscriber and the scheduled job is running on Publisher.
This means there’s no way that your Publisher instance can know what domain to use. You’ll need to manually set it somewhere.
I’d normally set it on the appropriate node(s) in the backoffice, then look it up programmatically via the domain service as @jemayn recommends.
If you’re only working with one TLD then you could always just just pop it in appsettings. I will often do this in multi-instance sites anyway where the backoffice instance needs to be able to see and/or talk to client instances.