Get the HomepageId

Posted by Community Admin on 04-Aug-2018 08:34

Get the HomepageId

All Replies

Posted by Community Admin on 02-Nov-2012 00:00

Hi,

I normally use this code to get the HomepageId from the config:

var homePageId = Config.Get<PagesConfig>().HomePageId;

But it seems to be deprecated now. It always returns an empty Guid. Tried to change the homepage a few times, but it doesn't matter. The PagesConfig.config is not changed.

So what is the solution to get the HomepageId now?

Thanks,
Daniel

Posted by Community Admin on 02-Nov-2012 00:00

var homePageId = Config.Get<PagesConfig>().HomePageId;
var homeId = Config.Get<ProjectConfig>().DefaultSite.HomePageId;

Just whipped this up on our new 5.2 dev site.  Note it's not a multi-site and I don't know how that behaves.

Both values returned the same ID (I'm assuming it's the real home page ID!)... Anyway, the 2nd one doesn't say it's deprecated so I'd go with that.

Oh yeah, the 1st one might have returned a value, rather than Guid.Empty because this WAS a 5.1 project, upgraded to 5.2...

Hope that works for you!

Posted by Community Admin on 05-Nov-2012 00:00

Thanks Stephen2,
I also noticed this second option, but it returns an empty Guid anyways.

@Sitefinity Team: could you let us know what method or property we can use to get this Id? I'm using Sitefinity 5.2. A fresh started project.

Thanks,
Daniel

Posted by Community Admin on 06-Nov-2012 00:00

Hi,

I tried to reproduce this problem locally and the method is really returning an empty Guid.
This is now a deprecated way to get the Id. So, to get the job done I recommend you using the following:

var site = SystemManager.CurrentContext.CurrentSite;
var homePageId = site.HomePageId;

The variable homePageId will now hold your Guid. Greetings,
Ivaylo Angelov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 30-Apr-2014 00:00

Ivaylo,

 I noticed that the SystemManager.CurrentContext.CurrentSite returns an object of type Telerik.Sitefinity.Multisite.MultisiteContext.SiteProxy.  This object does contain the HomePageId property, but if you are using the MultisiteManager and calling the function GetSite() you will get an object type "Telerik.Sitefinity.Multisite.Model.Site".  

 Any idea how to get a list of all sites with the HomePageId property?

 Thanks,
Craig

This thread is closed