Winsmarts.com

Microsoft MVP

MVP Logo

Awarded the Microsoft MVP Award.

Hosted By

blah!bLaH!BLOG!!

Implementing Consistent Navigation across Site Collections

Posted on 1/5/2008 @ 5:33 PM in #Sharepoint | 34 comments | 9215 views

One of the most important decisions you will make in planning out a SharePoint 2007 farm is the topology of your farm. Various criterion will drive you to choose between sites, or site collections between different areas of your application. Both, a site, or a site collection have their advantages or disadvantages.

Site Collections bring you the advantage of much better manageability, splitting amongst databases, security implementation, feature boundaries, and many others. But they come with disadvantages as well. One of the disadvantages is each site collection, insists to have it's own Menu. This can be confusing. Consider the following case -

  • You have a top level site collex - at "/".
  • You then have a child site at /child
  • and then yet another grandchild site at /child/grandchild1.
  • At the same time, you define a managed path called "child" with wildcard inclusion.
  • And then you create a /child/grandchild2, site collex.
  • Now in that scenario, /child/grandchild2 has no connection with /, or /child, or /child/grandchild1
    • grandchild 2 will have a tab called "home", which will point to "grandchild2"
    • grandchild2 won't appear in /'s navigation.
    • other inconsistencies.

Okay, the above is a contrived example, but very frequently, you as an architect are forced to split your sites into site collections (if nothing else, for scalability and sizing purposes).

So, how do you implement a consistent navigation between multiple site collections?

The answer - using a SiteMapProvider.

You can use any SiteMapProvider, but the easiest answer is to use the Microsoft.SharePoint.Navigation.SPXmlContentMapProvider. Here is how -

  • Add the following entry to your web.config(s) under the sitemap/providers node.

    <add name="CustomXmlContentMapProvider" siteMapFile="_app_bin/mainMenu.sitemap" type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  • In the same website(s), add a mainMenu.sitemap file with the following contents -
  • <siteMap>
      <siteMapNode title="Home Page" url="/">
        <siteMapNode title="Lists" url="
    http://moss2007/_layouts/viewlsts.aspx?BaseType=1">
          <siteMapNode title="Google" url="
    http://www.google.com"/>
        </siteMapNode>
      </siteMapNode>
    </siteMap>

    This file will control the actual content of the navigation.

  • Modify the master page, add the following inside a SharePoint:DelegateControl, preferably right next to topSiteMap declaration.
  • <asp:SiteMapDataSource
    ShowStartingNode="true"
    SiteMapProvider="CustomXmlContentMapProvider"
    id="xmlSiteMap"
    runat="server"
    />

  • Modify the master page, and change the SharePoint:AspMenu, with ID=TopNavigationMenu, change it's DataSourceID from "topSiteMap" to "xmlSiteMap".

Now you would note that I am modifying the top navigation, but this can be applied to anything that understands site maps - TreeViews, ASP:Menu's, BreadCrumbs - even your custom navigation controls.

That's it. Save and Run - your navigation on that site is now controlled via the XML file. Lather rinse, repeat, on all site collections you'd like this navigation to appear on, and you have consistent navigation - across site collections.


On 1/8/2008 3:42:26 PM Charlie Evans said ..
Thanks for the excellent article. In fact my team was just setting this up this week and ran into this issue. Do you know if there is a way to have multiple farms share the same mainMenu.sitemap so that we do not have to keep our three farm's navigation in sync manually?

On 1/8/2008 9:11:23 PM Sahil Malik said ..
Charlie - Multiple site collections can.
Multiple websites, and multiple farms cannot. But, nothing stops you from building a sitemap provider that is backed by a database, or an XML file that sits as web service at a common location. Regards, Sahil

On 1/29/2008 10:18:14 AM Mike said ..
Great article. It works fine - but only if I have disbaled the publishing infratsructure. If I enable this feature on a sitecollection it stops working and the site throws an unexpected error. Do you have any idea how I could work around this?

On 1/29/2008 11:27:47 AM Mike said ..
I solved it. I had to use a new delegate control inside the master page. thx

On 1/30/2008 1:53:33 PM Tom said ..
I couldn't get this to work at all for a publishing site--even with wrapping the SiteMapDataSource in a separate delegate control, like this: <!-- new XML site map -->
<SharePoint:DelegateControl runat="server" ControlId="XmlNavigationDataSource">
<Template_Controls>
<asp:SiteMapDataSource id="xmlSiteMap" ShowStartingNode="true" SiteMapProvider="CustomXmlContentMapProvider" runat="server"/>
</Template_Controls>
</SharePoint:DelegateControl> <!-- original site map -->
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource">
<Template_Controls>
<asp:SiteMapDataSource id="topSiteMap" ShowStartingNode="False" SiteMapProvider="SPNavigationProvider" runat="server" StartingNodeUrl="sid:1002"/>
</Template_Controls>
</SharePoint:DelegateControl> Any ideas?

On 3/17/2008 2:13:22 PM Charlie Evans said ..
We implemented this custom navigation about two months ago and it works great. Thank you. At the same time we also rolled it out to the My-Sites virtual directory. This works great for all but about 6 hours of the day. I have checked backups, file permissions, network traffic and can not come up with any cause for this. I was wondering if you had experienced anything similar?

On 4/13/2008 10:32:22 PM David said ..
Can this approach perform security trimming?
I noticed SharePoint uses the same SPXmlContentMapProvider in the web.config for the layouts.sitemap file but the two differences I see is that they use only subsets of this sitemap file at any one time and it is security trimmed and the URL for each node is always appended to the end of the current SharePoint site I am in. Would this require a custom provider to supply the security trimming? My end goal is to have my 50 site collections all point to a single source for a sitemap which creates a menu that is made up of the 50 site collections and security trims the navigation based on access to the individual site collections. The navigation is only two levels deep and I thought about using a single site collection to build a fake navigation hierarchy using the SharePoint web UI and audience targeting each link and then some how configure all other site collections to look at this single central site collection to build the top level navigation. 1. This means no custom UI needs to be built to edit the navigation. Do not need to know how to edit an XML sitemap file or have access to server.
2. It can be security trimmed using in built SharePoint audience targeting. (SharePoint will still deny access to the site anyway if a person hasn't got access to a site) So the question is how to make site collections look at another site collection to build the navigation. Any help would be greatly appreciated.

On 4/29/2008 7:37:11 AM Lauri V said ..
This article seems interesting, but doesn't help with my problem. I have 5 child sites which all have numerous grandchild sites and even the grandchild sites have grandgrandchilds. My problem is with the quicklaunch. It works just fine when navigating in grandchild sites. When I navigate to my grandgrandchild site I wanna see exactly the same navigation, but I see all the grandgrandchild sites. I don’t wanna use dynamic flyout menus in Quicklaunch. Can you help me with my problem? My quicklaunch while in grandchild site -grandchild 1
grandgrandchild 1
grandgrandchild 2
grandgrandchild 3
-grandchild 2
-grandchild 3
-grandchild 4
-grandchild 5 My quicklaunch while in grandgrandchild site. I want to see the same grandchild navigation “view” in both cases. -grandchild 1
grandgrandchild 1
grandgrandchild 2
grandgrandchild 3
-grandchild 2
grandgrandchild 1
grandgrandchild 2
grandgrandchild 3
-grandchild 3
grandgrandchild 1
grandgrandchild 2
grandgrandchild 3
-grandchild 4
grandgrandchild 1
grandgrandchild 2
grandgrandchild 3
-grandchild 5
grandgrandchild 1
grandgrandchild 2
grandgrandchild 3

On 5/3/2008 9:25:45 AM Benjamin said ..
Where do i create the mainMenu.sitemap file, is this in sharepoint or on the file system. If it is in sharepoint or the file system, how does the control know where to look for this file?

On 5/27/2008 6:16:18 PM Jason Lochan said ..
Awesome, clear, and to the point. Thanks!

On 5/29/2008 1:07:53 PM Ben said ..
I'm getting the following error: "An error occurred during the processing of . Type 'Microsoft.SharePoint.WebControls.DelegateControl' does not have a public property named 'SiteMapDataSource'." has anyone else had this problem and resolved it?

On 5/30/2008 10:32:37 AM Ben said ..
I fixed my problem, I missed the <Template_Controls>. However, how I'm having the same problem as Tom...it doesn't work when I turn on publishing and I have the same thing Tom does. How do I go about fixing this?

On 6/6/2008 10:47:37 AM tigirry said ..
This method works great if Publishing feature is NOT activated. I have the same problem that Tom and Ben have. Have anyone found a solution or workaround for this?

On 6/9/2008 10:10:53 AM Leon Zandman said ..
@tigirry: For a site that used the publishing feature try putting the SiteMapDataSource element from step 3 OUTSIDE of the DelegateControl element. It worked for me.

On 6/9/2008 10:23:25 AM Leon Zandman said ..
Sahil, If I set the ShowStartingNode attribute of the XmlSiteMap SiteMapDataSource to 'false' I get an "object reference not set" error message. Do you know why?

On 6/21/2008 10:26:57 AM Chinna said ..
Hi, Excellent artical. I have some problems with the navigation, we don't have tabbed navigation, no publishing features and have two site collections. Now how can we manage the BreadCrumbs accross the site collections.
The above example works fine, but when i move to Child/grandchild2 site collx. there is no way to go back to the root colletcion until have some link specified. Any Help will be appriciated

On 6/24/2008 5:56:14 PM Pankaj said ..
This is amazing...
Trust me, i have been hunting for last a few days on finding a solution on how to maintain a standard navigation across Site Collections and wasn't finding anything reliable. (I found some solutions like using the object model to add SiteNodes objects but this wasn't my requirement really. I dont wanna flush the NodesCollection and recreate the whole thing from the source XML file everytime my Feature gets activated or say my master page gets loaded). Finally I was thinking or writing a custom web control to read the data from an xml file and build the navigation manually in that control, but then luckily today I came to know that such a control already exists and is provided by the almighty MSFT...LOL Thanks a ton again for this article... Pankaj

On 7/2/2008 8:42:31 PM SP said ..
Going back to David's comments on 4-13, I am in the same boat. Looking to have a common, security-trimmed, navigation but across 50-60 site collections. Thoughts?

On 7/2/2008 11:00:06 PM Sahil Malik said ..
Sorry I've been too busy to respond (I was hoping someone else would - LOL). The top menu cannot be security trimmed - because it is not built the same way security trimmable content is built. In order to security trim the top menu, you will have to implement your own site map provider. Also search my blog for "Enhancing SPSecurityTrimmedControl", and that may give you a few ideas as well. Regards, Sahil

On 7/8/2008 5:10:58 PM mickymcb said ..
great article (as always)... one question, though... why not just override the delegate control rather than changing the master page?

On 7/11/2008 3:28:17 AM Shastry said ..
Thank you for the article. I set up our navigation exactly according to this article. It works when an admin logins into the portal for the first time and then regular users can login (assuming its caching the menu when the admin logs in). However, if the admin doesnt login the first time the application starts and a regular users tries to login I get this error: The file _app_bin/mainMenu.sitemap required by XmlSiteMapProvider does not exist.
Any ideas?

On 7/11/2008 3:30:09 AM Shastry said ..
Thank you for the article. I set up our navigation exactly according to this article. It works when an admin logins into the portal for the first time and then regular users can login (assuming its caching the menu when the admin logs in). However, if the admin doesnt login the first time the application starts and a regular users tries to login I get this error: The file _app_bin/mainMenu.sitemap required by XmlSiteMapProvider does not exist.
Any ideas? Yes, our site has publishing enabled and I tried some of the suggestions mentioned here like moving the declaration outside template controls etc to no avail.

On 7/15/2008 1:31:17 PM McArthur Robinson said ..
I am a junior Sharepoint developer working on in a MOSS environment and we are trying to get a consistent look and feel across several Site Collections. When I tried the above example I get an error when I ran the SharerPoint Site.
Is it possible for me to get a screen shot of each steps. What I did
1. Create a siteMap with two nodes name mainMenu.sitemap
www.yahoo.com
www.msn.com
2. add the mainMenu to my web application
inetPub\wwwroot\dev2-inside.net\_app_bin
3. Modify the master page, add the following inside a SharePoint:DelegateControl.
4. Add the following entry to your web.config(s) under the sitemap/providers node. Thanks

On 7/17/2008 9:37:15 AM Brian Edwards said ..
Thanks for this posting - really useful.
With regards to publishing sites, when non-admin users were hitting the site the first time they too were receiving the error:
The file _app_bin/mainMenu.sitemap required by XmlSiteMapProvider does not exist. In my case I solved this by placing the mainMenu.sitemap in a different location (for my project /_layouts/1033/Customisations/ folder). It now appears to be working fine!

On 7/17/2008 10:20:49 AM Sahil Malik said ..
Thank you Brian.

On 7/30/2008 5:41:47 PM Hung said ..
do you have the exact location that I need to change in the default.master

On 8/25/2008 4:57:28 PM Drallimer said ..
Excellent article! Very helpful. I was able to make this work after I made sure that the .sitemap file i was using was readable to the MOSS process account. I read in the following links that it would be possible for this approach to security-trim the results, but so far I haven't been able to make it happen. Does security trimming work for you with this approach? Thanks, Dave. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spxmlcontentmapprovider_members.aspx http://msdn.microsoft.com/en-us/library/ms178428(VS.80).aspx

On 9/7/2008 12:51:04 PM Masud said ..
Great post. But I have additional query like : What is the max depth of flyout can I make using this method. I would appreciate your guideline in this regard.

On 9/17/2008 10:46:52 AM Ben said ..
Leon,
Thanks for the info about putting the SiteMapDataSource element from step 3 OUTSIDE of the DelegateControl element, it fixed the problem of getting the navigation working with publishing turned on.

On 9/29/2008 1:15:32 PM Masud said ..
This is a question for Brian Edward. I tried with placing the sitemap file in /_layouts/1033/Customisations folder but still users other than Admin gets error when publishing is on. Any help to solve the problem will be highly appreciated.

On 9/29/2008 1:16:30 PM Masud said ..
Can anybody help me how could I make breadcrum working using the same sitemap.

On 10/7/2008 2:42:55 PM rajesh said ..
Does the SPXmlContentMapProvider expect the siteMap file to be in app_bin folder? I have a situation where the different site collections created under single web app might have its own navigation structure. So I would like to place the sitemap file in a document library in each of the site collections, so that navigation could be unique. Is this possible? I see that SiteMapDataSource does not expect any parameter for sitemap url.

On 10/28/2008 6:55:17 PM erik said ..
I too would like to know if we can use the same mainMenu.sitemap to develop a custom breadcrumb to reflect the same path?

On 11/10/2008 7:11:39 AM dejawoo said ..
my earlier thoughts were that SPXMLContentSiteMapProvider would not have a security trimming feature but through enabling securityTrimmingEnabled="true" in my provider definition I noticed that Providers IsAccessibleToUser(HttpContext context, SiteMapNode node) get called. Am I overlooking anything? if No then what s the point of implementing custom provider.
Thanks.
P.S. using merits of Reflector I just been assured in additional.

Please post your comments:


Your feedback will be submitted for moderation, and will appear after it is approved.

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Site designed and maintained by Sahil Malik | All Rights Reserved. ©2007 WinSmarts.com.