Implementing Consistent Navigation across Site Collections

Posted on 5/24/2010 @ 8:30 PM in #SharePoint by | Feedback | 19811 views

(Also see - Security Trimmed Cross Site Collection Navigation)

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.

Sound off but keep it civil:

Older comments..


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.


On 2/12/2009 11:13:57 AM Amandeep Singh said ..
I got little confuse with the blog so have some questions to you. I am in the same situation as you have mentioned earlier in your blog "contrived example" and try to navigate(list) all the sites (/child/G-child1 and /child/Gchild2(managed path wildcard inclusion) under '/' on its home page. So far i am just able to navigate '/child/Gchild1' sites and subsites, but i also want to naviagte all the managed path site collections. Would your code help me to accomplish it?


If so, on which site's config file you want me to put it?

Actually i am newbie to SharePoint, so missing much of its understanding. Thanks in advance.


On 2/12/2009 11:14:15 AM Amandeep Singh said ..
I got little confuse with the blog so have some questions to you. I am in the same situation as you have mentioned earlier in your blog "contrived example" and try to navigate(list) all the sites (/child/G-child1 and /child/Gchild2(managed path wildcard inclusion) under '/' on its home page. So far i am just able to navigate '/child/Gchild1' sites and subsites, but i also want to naviagte all the managed path site collections. Would your code help me to accomplish it?


If so, on which site's config file you want me to put it?

Actually i am newbie to SharePoint, so missing much of its understanding. Thanks in advance.


On 4/17/2009 7:50:46 PM Phil said ..
I have completed all of the steps as instructed but I am receiving the following error:

"Unable to get the private bytes memory limit for the W3WP process. The ASP.NET cache will be unable to limit its memory use, which may lead to a process restart. Error: 0x80070005"

Please assist in helping me to determine how to resolve this issue.


On 4/22/2009 4:47:59 PM Phil said ..
I have figured it out. You must add a new SharePoint:DelegateControl inside the master page. Do NOT add the asp:SiteMapDataSource inside the existing DelegateControl.


On 4/29/2009 3:59:55 PM Ben said ..
In agreement with Dejawoo, I am not sure why this doesn't allow security trimming. The provider is a SPXmlContentMapProvider which does URL- and File- trimming out of the gate using the is IsAccessibleToUser() member. Although I have it enabled, it isn't trimming properly but all indications are that it should.

Does anyone have a detailed reason as to why it isn't? Sorry Sahil, I don't mean disrespect, but "The top menu cannot be security trimmed - because it is not built the same way security trimmable content is built. " kinda doesn't cut it. =)


On 5/17/2009 3:35:58 AM Ali raza said ..
How to make current navigation highlighted using this solution. i want to make current tab highlighted


On 9/7/2009 4:34:51 PM Rob said ..
I did this but only I can see the new navigation. Any thoughts on what I might have missed? The master page is definitely checked *IN*. That's the only thing that I could think of that might've stopped it from working.


On 10/28/2009 4:12:22 PM dinesh said ..
Hi,

Thanks for a great article. I was able to get everything working. However, is there a way to make the selected link/page highlighted. Seems like the <StaticSelectedStyle CssClass="topNavSelected"/> is not being applied.

Thanks!


On 11/19/2009 10:18:09 AM Sanjib said ..
Hi,


I am not able to highlight the selected tab. Can anyone please help me to resolve the issue?


Thanks


On 4/19/2010 7:53:01 AM eru said ..
SharePoint is a hotpot of BS when it comes to making changes like this.


It is ridiculously difficult.


On 7/4/2010 2:19:24 PM Milind said ..
Anyone tried this in Sharepoint 2010, it appends the relative site url to the url specified,so from root site it works as 2007 but from subsite it's (URL's) all messed up.


On 7/9/2010 3:53:23 PM Ray said ..
@Milind - same issue here in SP 2010, works for the root site, but breaks in a site collection (unless you used relative paths only). Tried adding securityTrimmingEnabled="false" to the provider entry in web.config but does not help. Frustrating because need to refer to non-relative sites too in our global nav.


On 7/12/2010 7:34:05 AM James said ..
I have the same as the two above posters in SP Foundation 2010.

Tried in different formats: ~/mainsite, /mainsite, mainsite http://server/mainsite just makes it relative to the current site.


On 7/14/2010 9:28:36 AM Kevbo said ..
Same issue as the three posters above me.


The links only work if you use relative links which I can't since I need to link to other site collections and web apps. So close to solving my issue but I guess I am back to square one :(

Anyone find any solutions or workarounds for this and Sharepoint 2010?


On 7/14/2010 10:39:20 AM Sahil Malik said ..
For the above issue, please see the link called "Security Trimmed Cross Site Collection Navigation"


On 11/15/2010 2:35:33 PM Dave said ..
Anyone fix the problem with the relative links, etc? The Security Trimmed link doesn't work.


On 11/16/2010 12:24:07 PM Sahil Malik said ..

On 4/8/2011 6:56:40 AM Labhesh said ..
Hi,


1. is there way to have these features enabled for publishing site. (across site collection).


2. Any possiblities for across webs.


On 5/9/2011 4:33:58 PM Chris Byrom said ..
I had the same problem as many above with SharePoint 2010.

To fix this use the standard XMLSiteMapProvider instead of SharePoint's.

So in the web.config I used this for the type entry "System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

After doing this the URLs started working as they did in MOSS 2007.

Hope this helps someone, took me about an hour to figure it out.


On 8/10/2011 3:25:26 AM Sandra said ..
Hi,


i have a problem, the navigation works fine, but sites Site Settings, View all site content and Site Permissions still show navigation that is set in Look and Feel -> Navigation. Any idea how to fix this?


On 9/17/2011 3:53:01 AM Rauf said ..
Good post but not working on SharePoint 2010. How will it work i have tried 3 times but website is giving error, how to achieve this a very nice post??????????


On 9/18/2011 3:03:48 PM Prakash said ..
it works. i have 4 site collections (intranet,media,resources). i can go to root page of media from intranet. But, when i am in media and click media menu, it will take me to media/SitePages/Forms/AllPages.aspx and again if i click the same media menu, it would again take me to media/SitePages/Forms/AllPages.aspx?RootFolder=%2fsites%2fmedia%2fSitePages%2fForms&FolderCTID=0x012001.

Anyone knows why this is happening?


On 9/21/2011 9:38:05 AM Erin said ..
Hi All,


For those of you having trouble with this in shareponit 2010, see the 3rd last post at the bottom of this link .. it's what worked for me.


http://social.msdn.microsoft.com/Forums/pl-PL/sharepoint2010general/thread/617062ff-d23d-4b95-8bfe-838988f9774c


Thanks,


On 9/12/2012 12:50:29 PM Sam said ..
Hiya,


Not sure if someone can still answer to this thread and my questions ? I have managed to get this working on 1 web app but on a 2nd separate web app, this doesn't seem to be working at all. The site with the respective master page for xmlsitemap just keeps crashing with "unexpected error" thrown. the setup on both web apps is exactly the same.

could someone advise if I can try something to fix this please?

thanks in advance


Sam


On 9/19/2012 3:47:54 AM karim said ..
hi

I am using same procedure in sharepoint foundation to implement Toplink bar dropdown.


But all the links are working fine in Root site but not in the subsites.I have nearly 10 subistes ans subsites.


So Could you please help me on this issue.

regards,


karim