SaaS CMS has officially launched! Learn more now.

SiteDefinition.StartPage returns ID 0 in InitializableModule



I am trying to write a migration system which on startup creates all the new pages automatically. I use IInitializableModule for this, and in only one of our two projects I cannot access the StartPage inside Initialize() method. Later it is accessible.

    public class MigrationTasksInitializableModule : IInitializableModule

        public void Initialize(InitializationEngine context)


/* here EPiServer.Web.SiteDefinition.Current.StartPage returns:
ID = 0, WorkID = 0, ProviderName = null
    GetPublishedOrLatest: false
    ID: 0
    IsExternalProvider: false
    IsReadOnly: true
    ProviderName: null
    WorkID: 0



        public void Uninitialize(InitializationEngine context)


What am I doing wrong?



Edited, May 07, 2021 19:45

Do you have only one start page, or is it a multi site solution?

May 07, 2021 19:48

In the project where I only get ID=0, it is a single site solution with a single start page. In StartPage's controller later for instance I can access it.

I can access it through ISiteDefinitionRepository, but still strange.

Edited, May 07, 2021 19:55

Looks like what you are experiencing is expected:

If you in one project get the StartPage-value, maybe you are just lucky with the order of initialization.

The quick-and-dirty solution would be adding the content id to your start page to appsettings, and use that id in your initialization module.

May 08, 2021 7:58

Hi Zsolt

Do your site have a host definition with a wildcard ("*") for a hostname?

A site with this wildcard will be returned when the site cannot be determined.

May 10, 2021 4:50

Thank you for your answers, it explains the behavior. I will use SiteDeinifitonRepository in all cases to fetch the start page with the expected type, it works in all cases.

May 10, 2021 6:40
Praful Jangid - May 10, 2021 12:01
If this issue is resolved, can you please mark it as ANSWERED?
Thanks :)
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.