Site definition id in DXP

Vote:
 

Hello,

When i do Sitedefinition.current.id , I get value when running in local while the same thing resolves to empty guid when deployed in DXP. Why would that be ?

#249690
Mar 07, 2021 23:47
Vote:
 

Are you running in context of a scheduled job? 

#249717
Mar 08, 2021 9:07
Vote:
 

Hello Quan,

No am not running in schedule job context. I am calling profile store api and using site id as one of the parameter from website itself (since my applicaiton has multi site) to filter site content accordingly.

This seems to be working fine while in local but in DXP it always gives me empty GUID

#249731
Mar 08, 2021 16:19
Vote:
 

When you run following code, does it gives you list of Sites?

var siteDefinitionRepository = context.Locate.Advanced.GetInstance<ISiteDefinitionRepository>();
var siteDefinitions = siteDefinitionRepository.List();
#249782
Mar 09, 2021 20:18
Vote:
 

Here's the code I use in DXP environment to get the siteId and do something with it. However we only have one site, you may need to change ContentReference.StartPage accordingly if you have multiple sites.

public void Initialize(InitializationEngine context)
{
    var resolver = context.Locate.Advanced.GetInstance<ISiteDefinitionResolver>();
    var site = resolver.GetByContent(ContentReference.StartPage, fallbackToWildcard: true, fallbackToEmpty: false);
    var siteId = site.Id;
    
//Your logic here }
#252783
Apr 09, 2021 8:08
* 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.