Monday, June 15, 2009

PortalSiteMapProvider randomly drops off pages

I built custom navigation for the http://nzte.govt.nz website using the PortalSiteMapProvider.
This is a powerful ally in the SharePoint Publishing Site world as it handles caching and security trimming. It also means that when you use one of the built-in instances of the PortalSiteMapProvider like CurrentNavSiteMapProvider you can use the navigation edit menu under Site Actions->Site Settings to hide/show sites and pages, change the order and add new links.

One thing that was unexepected was that every now and then the PortalSiteMapProvider would not return pages. We had content editors showing us screenshots of the menu showing only sites. This was easy to replicate by pressing F5 repeatedly until eventually it would happen (around 20-40 refreshes).
Now by default the propoerty IncludePages is set to PerWeb, so in attempt to fix the issue I added IncludePages="Always" to the web config as follows:

<add name="CurrentNavSiteMapProvider" .... includepages="Always" dynamicchildlimit="0">

but this didnt help.

The answer is to set the IncludePages property in your code block when you are building your navigation as follows:


PortalSiteMapProvider psmp = PortalSiteMapProvider.CurrentNavSiteMapProvider;
psmp.IncludePages = PortalSiteMapProvider.IncludeOption.Always; //resetting as it sometimes drops off
SiteMapNode siteMapNode = psmp.FindSiteMapNode(elevatedWeb.ServerRelativeUrl);
List leve1ItemList = new List();
for (int i = siteMapNode.ChildNodes.Count - 1; i >= 0; i--)
{
leve1ItemList.Add(siteMapNode.ChildNodes[i]);
}
leve1ItemList.Reverse();
level1Repeater.DataSource = leve1ItemList;
level1Repeater.DataBind();
}


One other thing is to set the DynamicChildLimit in the web config as by default it only displays 50 and if you have over 50 items it can also cause unexcept results like not displaying anything at all. As you can see above I have set it to 0 which means it has no limits.

No comments:

Post a Comment