+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get the HomepageId

Get the HomepageId

5 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    02 Nov 2012
    Link to this post
    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
  2. Stephen2
    Stephen2 avatar
    94 posts
    Registered:
    05 Feb 2012
    02 Nov 2012
    Link to this post
    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!
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    05 Nov 2012
    Link to this post
    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
  4. Ivaylo Angelov
    Ivaylo Angelov avatar
    68 posts
    Registered:
    27 Oct 2016
    06 Nov 2012
    Link to this post
    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
  5. Craig
    Craig avatar
    82 posts
    Registered:
    07 Apr 2009
    30 Apr 2014 in reply to Ivaylo Angelov
    Link to this post

    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

5 posts, 0 answered