November Happy Hour will be moved to Thursday December 5th.

ContentLoader works localy but not on server

Vote:
 

Hi,

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)
    {
        RouteTable.Routes.Ignore("sitemap.xml/{*pathInfo}");

        if (ContentReference.IsNullOrEmpty(ContentReference.StartPage))
            return;

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



#145942
Mar 16, 2016 8:07
Vote:
 

Tried 

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

and then use ServiceLocator?

#145943
Mar 16, 2016 8:23
Vote:
 

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

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



#145944
Mar 16, 2016 8:36
Vote:
 

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).

#146521
Mar 17, 2016 9:48
Vote:
 

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.

#146524
Mar 17, 2016 10:08
Vote:
 

Works like a charm! Thank you all.

#146525
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.