Try our conversational search powered by Generative AI!

Empty StartPage reference in IInitializableModule


I'm trying to access the StartPage in a custom IInitializableModule using ContentRepository, but ContentReference.StartPage is empty:

[ModuleDependency(typeof (EPiServer.Web.InitializationModule))]
	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?

Jan 28, 2015 12:46

The InitializableModule looks fine.

Do you have * in hostname?

Jan 28, 2015 13:06

No, I have localhost and a couple of hostnames. But how does this affect ContentRepository.StartPage not being set?

Jan 28, 2015 13:18

When your code executes outside of web request (init module, scheduled jobs, etc.), then you need to add * in the list of hostnames.

Jan 28, 2015 13:26

I see... Is there any other way of obtaining the start page without setting * as host name?

Jan 28, 2015 13:36

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

Jan 28, 2015 14:14
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.