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

Empty StartPage reference in IInitializableModule

Vote:
 

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?

#116307
Jan 28, 2015 12:46
Vote:
 

The InitializableModule looks fine.

Do you have * in hostname?

#116308
Jan 28, 2015 13:06
Vote:
 

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

#116310
Jan 28, 2015 13:18
Vote:
 

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

#116312
Jan 28, 2015 13:26
Vote:
 

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

#116313
Jan 28, 2015 13:36
Vote:
 

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

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