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

Forums / General Discussions / Using Fluent API to see check if current page is homepage

Using Fluent API to see check if current page is homepage

7 posts, 0 answered
  1. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    06 Dec 2010
    Link to this post
    Hi,

    Need to check whether the current page is the homepage... can't work out how to do this using the fluent API.

    Has anyone got a sample?

    Thanks,

    Seth
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    06 Dec 2010
    Link to this post
    Hello Webinsite,

    You can use

    PagesConfig conf = new PagesConfig();
    var id = conf.HomePageId;


    Then you can use Pages facade and get the page by Id.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    06 Dec 2010
    Link to this post
    Thanks Ivan for such a speedy response.

    So is this reasonably efficient:

    public bool isHomepage()
            {
                SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
                PageSiteNode node = (PageSiteNode)currentNode;
     
                PagesConfig conf = new PagesConfig();
                if(node.PageId == conf.HomePageId)
                    return true;
                return false;
            }


    Cheers,

    Seth
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    07 Dec 2010
    Link to this post
    Hello Webinsite,

    This code should be siffucient.

    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Haydn
    Haydn avatar
    13 posts
    Registered:
    13 May 2008
    09 Dec 2010
    Link to this post
    Hi Ivan,

    Sadly, I didn't have as much luck with this code, the following code always seems to output an empty Guid, 00000000-0000-0000-0000-000000000000

    PagesConfig pageConfig = new PagesConfig();
     
    Response.Write(pageConfig.HomePageId.ToString());

    I have "Set as homepage" on a page within the Sitefinity admin and checked to see if there was any permissions that might prevent it from returning the actual homepage id. Everything seems in order.

    Digging a bit deeper, i have looked at the /app_data/sitefinity/configuration/pagesConfig.config, and the homePageId attribute appears to be set.

    <pagesConfig homePageId="fcf21816-64c5-4890-8bee-146dc3fceb31" defaultFrontendTemplateId="7aee4a2a-1d1e-4a03-97bb-2159e6a71bae" xmlns:config="urn:telerik:sitefinity:configuration" xmlns:type="urn:telerik:sitefinity:configuration:type" config:version="4.0.910.0" />

    Additionally, when trying the following code.....

    PagesConfig pageConfig = new PagesConfig();
     
    Response.Write(pageConfig.DefaultFrontendTemplateId.ToString());
     
    // Outputs : f669d9a7-009d-4d83-bbbb-000000000003

    Which suggests to me that the PagesConfig() does not nessasarily load data from /app_data/sitefinity/configuration/pagesConfig.config? 

    Any ideas what could be going wrong?

    Note: am calling the above code from a User Control embedded on a page.

    Many Thanks

    Haydn
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Dec 2010
    Link to this post
    Hi Haydn,

    There is a method in PageFacade called - SetAsHomePage() which we use and it explicitly sets the homepage id to the configuration. You can perform the following query

    var configManager = Config.GetManager();
    var config = configManager.GetSection<PagesConfig>();
    var id = config.HomePageId;


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Haydn
    Haydn avatar
    13 posts
    Registered:
    13 May 2008
    13 Dec 2010
    Link to this post
    Thanks Ivan,

    That seems to work :)

    Kind Regards

    Haydn
7 posts, 0 answered