SiteMapBase.GetActualCurrentNode returns null

Posted by Community Admin on 05-Aug-2018 11:14

SiteMapBase.GetActualCurrentNode returns null

All Replies

Posted by Community Admin on 01-Feb-2011 00:00

Hello
The code below for getting the current page is returning null when used in Page_Load on a template masterpage:

var psn = SiteMapBase.GetActualCurrentNode();

Is this the wrong place to use this code?

Thanks
Ryan

Posted by Community Admin on 01-Feb-2011 00:00

A little more testing, and this only occurs on the homepage of the site, if I don't specify the page "/home"  in the url address bar. Clicking on "Home" in the menu, and the code returns the PageNode. What is the solution here, to get the root node?

Posted by Community Admin on 01-Feb-2011 00:00

My quick fix:

01.PageManager pageManager = new PageManager();
02.var psn = SiteMapBase.GetActualCurrentNode();
03.PageNode pgn1;
04.if (psn != null)
05.
06.    pgn1 = PageManager.GetManager().GetPageNode(psn.Id);
07.
08.else
09.
10.    PagesConfig pagesConfig = Config.Get<PagesConfig>();
11.    pgn1 = pageManager.GetPageNode(pagesConfig.HomePageId);
12.

Posted by Community Admin on 02-Feb-2011 00:00

Thanks, I had this same issue and this post helped.

I made a function for finding the Guid of the current page ...

01.public static Guid GetCurrentPageId()
02.
03.    Guid pageId;
04.    PageSiteNode psn = SiteMapBase.GetActualCurrentNode();
05.    if (psn == null)
06.    
07.        PagesConfig pagesConfig = Config.Get<PagesConfig>();
08.        pageId = pagesConfig.HomePageId;
09.    
10.    else
11.    
12.        pageId = psn.Id;
13.    
14.    return pageId;
15.

This thread is closed