ContentLoader works localy but not on server



I have a RouteInitializer that then everything works should initialize a PartialRouter. Everything works fine on my local environment, but as soon as I deploy it to the server GetChildren stop returning items. 

Could it be that things run in another order on the server? Do I need another ModuleDependency? 

Here is my code (productsPages will be empty):

public class RouteInitalizer : IInitializableModule
    public EPiServer.ServiceLocation.Injected contentLoader { get; set; }

    public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)

        if (ContentReference.IsNullOrEmpty(ContentReference.StartPage))

        var productsPages = contentLoader.Service.GetChildren(ContentReference.StartPage);
        var productsPage = productsPages.FirstOrDefault();
        if (productsPage != null)
            var partialRouter = new ProductRouter(productsPage.ContentLink.ToReferenceWithoutVersion());

Mar 16, 2016 8:07


[ModuleDependency(typeof (EPiServer.Web.InitializationModule))]

and then use ServiceLocator?

Mar 16, 2016 8:23

Oh, sorry. missed a bit of code...

[ModuleDependency(typeof(ServiceContainerInitialization), typeof(EPiServer.Web.InitializationModule))]
public class RouteInitalizer : IInitializableModule

Mar 16, 2016 8:36

Note that when you use GetChildren without specyfing a language (a LanguageLoaderOption) then the language will be resolved from the context. In case of a normal web request that language is determined from the url (either through host mapping or language segment). However an initializable module is likely to run outside a normal webrequest so in that case is langauge resolved using other available sources like globalization element in web.config.

To ensure a deterministic behaviour I suggest that you expliciclty specify a language when loading content from an initializable module (you can use fallback to master or use LanguageLoaderOption.MasterLanguage() or LanguageSelector.MasterLanguage if you do not know the language at forehand).

Mar 17, 2016 9:48

Good point! I had some problems with scheduled job that was related to that @Johan. I had some settings on startpage I got on the scheduled job that worked fine on dev,test and stage but bombed on production for the same reason. EPiServer got the wrong language version on production. Took me a while to resolve and quite a few swear words. So specifying language when you dont have the normal web context = important.

Mar 17, 2016 10:08

Works like a charm! Thank you all.

Mar 17, 2016 10:13
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.