I'm trying to access the StartPage in a custom IInitializableModule using ContentRepository, but ContentReference.StartPage is empty:
public class MyModule : IInitializableModule
public void Initialize(InitializationEngine context)
var contentRepo = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance();
var startPage = contentRepo.Get(ContentReference.StartPage);
// Do stuff with startPage...
I've set the start page in Admin mode, and I can retrieve the start page using the same method in other parts of my code. I've also added the ModuleDependency attribute for InitializationModule - is there anything else I need to wait for?
The InitializableModule looks fine.
Do you have * in hostname?
No, I have localhost and a couple of hostnames. But how does this affect ContentRepository.StartPage not being set?
When your code executes outside of web request (init module, scheduled jobs, etc.), then you need to add * in the list of hostnames.
I see... Is there any other way of obtaining the start page without setting * as host name?
Maybe, but the wildcard option is the simplest one :)
It also solves the problem when localhost (dev machine) and your_test_site (site on remote server) share the same database.EPiServer can redirect you from localhost to your_test_site, which can be annoying sometimes :)
I usually use the wildcard instead of localhost, and public hostname for test/staging/prod