volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

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?

#116307
Jan 28, 2015 12:46

The InitializableModule looks fine.

Do you have * in hostname?

#116308
Jan 28, 2015 13:06

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

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

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