SiteDefinition.StartPage returns ID 0 in InitializableModule

Vote:
 

Hi,

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.

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

Thanks,

Zsolt

#254500
Edited, May 07, 2021 19:45
Vote:
 

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

#254501
May 07, 2021 19:48
Vote:
 

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.

#254502
Edited, May 07, 2021 19:55
Vote:
 

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.

#254537
May 08, 2021 7:58
Vote:
 

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.

#254604
May 10, 2021 4:50
Vote:
 

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.

#254605
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 :)
* 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.