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

Forums / Sitefinity SDK / SiteMapBase.GetActualCurrentNode returns null

SiteMapBase.GetActualCurrentNode returns null

4 posts, 0 answered
  1. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    01 Feb 2011
    Link to this post
    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
  2. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    01 Feb 2011
    Link to this post
    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?
  3. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    01 Feb 2011
    Link to this post
    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.}
  4. Kevin
    Kevin avatar
    19 posts
    Registered:
    30 Sep 2010
    02 Feb 2011
    Link to this post
    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.}
4 posts, 0 answered