Building a Security Trimmed Navigation Control for SharePoint 2007
I am in the process of migrating some Portals from SPS 2003 to MOSS 2007 for a client.
The custom global navigation web part in SPS 2003 that was used on this client's site used the object model to enumerate the links across all the SPS03 portals on that particular web server. There also was a custom "My Team Sites" application that listed the sites that a particular user belonged to.
For the MOSS 2007 migration, since security trimming is ubiquitous in MOSS, it makes sense to simply have a global navigation control that enumerates all of the links across the portals and security trims for each particular user - eliminating the "My Team Sites" application completely.
I have looked at a couple of SharePoint blogs that talk about using the Object Model, and in particular, the SPWeb method, GetSubWebsForCurrentUser. But after some experimentation, it seems that this method does not work with AD security groups. It returns all webs for which the user is an explicit member, but not those where they are a member by virtue of a security group that they belong to.
After spending some time working with the PortalSiteDataMapProvider, I am able to get a security trimmed nav for each user using the following code:
PortalSiteMapProvider portalProvider = PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode;
portalProvider.DynamicChildLimit = 25;
portalProvider.IncludeSubSites = PortalSiteMapProvider.IncludeOption.Always;
portalProvider.IncludePages = PortalSiteMapProvider.IncludeOption.Never;
portalProvider.IncludeHeadings = false;
portalProvider.IncludeAuthoredLinks = false;
SiteMapNode rootNode = (PortalSiteMapNode)portalProvider.RootNode;
SiteMapNode currentNode = (PortalSiteMapNode)portalProvider.CurrentNode;
You can either get the nodes by calling:
Or by getting the child nodes for each node:
I still need to get the SiteDataMap for all the web applications other than the current web application. And this is proving to be a bit more difficult.