Thursday, November 3, 2011

Consistent SharePoint Navigation Across Site Collection and Web Applications


Multiple site collections on multiple web applications, the problem is SharePoint will only be "aware" navigation in the the site collection.

So we need to have all the web apps, master pages and sitemaps use a custom sitemap provider.

for example:

 <siteMap>
  <siteMapNode title="xxx" url="">
    <siteMapNode title="xxx" url="/">
        <siteMapNode title="xx" url="/xx/"/>
        <siteMapNode title="x x" url="/xx/"/>
        <siteMapNode title="x" url="/x/"/>
    </siteMapNode>
    <siteMapNode title="x" url="/sites/x"/>
    <siteMapNode title="x" url="/sites/x"/>
    <siteMapNode title="x" url="/sites/x"/>
    <siteMapNode title="x" url="/sites/x"/>
  </siteMapNode>
    <siteMapNode title="x" url="app1/sites/x"/>
  </siteMapNode>
</siteMap>

Add this to _app_bin, save as mainMenu.sitemap.  This folder has special permissions, like anonymous access.

In the master page find the top nav and put this in


<SharePoint:AspMenu ID="TopNavigationMenuV4" Runat="server" EnableViewState="false" DataSourceID="topSiteMap1" AccessKey="<%$Resources:wss,navigation_accesskey%>" UseSimpleRendering="true" UseSeparateCss="false" Orientation="Horizontal" StaticDisplayLevels="1" MaximumDynamicDisplayLevels="1" SkipLinkText="" CssClass="s4-tn"/> <SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource1" Id="topNavigationDelegate"> <Template_Controls> <asp:SiteMapDataSource ShowStartingNode="false" SiteMapProvider="CustomXmlContentMapProvider" id="topSiteMap1" runat="server" /> </Template_Controls> </SharePoint:DelegateControl>





Problem: SharePoint Desginer and VS 2010 will crash if you make errors here
Must be same rendering engine?  Wierd.

then in the web.config find the siteMap section and add



Except don't use that one it would be to easy.  The above one will append to the url. So it will never work.

Instead use this assembly...
System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Voila - complete control over navigation just the way I like it.

Also this can be done in a feature...

No comments: