Using Fluent API to see check if current page is homepage

Posted by Community Admin on 03-Aug-2018 14:57

Using Fluent API to see check if current page is homepage

All Replies

Posted by Community Admin on 06-Dec-2010 00:00

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

Posted by Community Admin on 06-Dec-2010 00:00

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

Posted by Community Admin on 06-Dec-2010 00:00

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

Posted by Community Admin on 07-Dec-2010 00:00

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

Posted by Community Admin on 09-Dec-2010 00:00

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

Posted by Community Admin on 09-Dec-2010 00:00

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

Posted by Community Admin on 13-Dec-2010 00:00

Thanks Ivan,

That seems to work :)

Kind Regards

Haydn

This thread is closed