SIGN UP MEMBER LOGIN:    
ARTICLE

Implementing multiple sitemaps

Posted by Scott Davis Articles | C# Language October 25, 2007
This article explains how to control the display of nodes for different user, while using treeviews and sitemaps.
Reader Level:

We have a requirement in our current application to have a dynamic navigation system where certain links are shown or hidden depending on where you are within the application itself and also based upon your assigned role. ASP.NET 2.0 provides some nice controls to handle this right out of the box.

We chose to use the TreeView control to render our navigation system. The treeview uses the SiteMapDataSource as it's datasource. Trimming the huge navigation tree by roles was pretty easy as it consisted of one attribute in the default sitemap provider element in the web.config being set to true,

securityTrimmingEnabled="true"
   

and then defining which role you wanted to allow to each branch or node in the actual web.sitemap file itself.


<siteMapNode url="my/webpage.aspx" title="MyWebPage" roles="*">

That was about all we needed to get the Roles working getting multiple sitemaps up and running turned out to not be that much more difficult.

To enable your site to contain more than one sitemap all you need to do is to add new providers to the siteMap element in your web.config.  For example, out of the box your web.config is configured to use a single provider like this:


<siteMap defaultprovider="DefaultSiteMapProvider" enabled="true">

<providers>

<add name="DefaultSiteMapProvider" description="Default SiteMap provider" type="System.Web.XmlSiteMapProvider" sitemapfile="web.sitemap" securitytrimmingenabled="true"></add>

</providers>

</siteMap>

<!--To add more sitemaps - add more providers-->

<siteMap defaultprovider="DefaultSiteMapProvider" enabled="true">

<providers>

<add name="DefaultSiteMapProvider" description="Default SiteMap provider" type="System.Web.XmlSiteMapProvider" sitemapfile="web.sitemap" securitytrimmingenabled="true"></add>           

<add name="MySiteMapProvider" description="My SiteMap provider. " type="System.Web.XmlSiteMapProvider" sitemapfile="myWeb.sitemap" securitytrimmingenabled="true"></add>

</providers>

</siteMap>

Once you have your additional providers configured in the web.config, then all you need to do is to bind your SiteMapDataSource to one of the providers. You can have many SiteMapDataSources on a single page as well, such as in a masterpage. Then, changing the sitemap being used by the current page or users role is done programatically by assigning the DataSourceID of the navigation control to the ID of the SiteMapDataSource that you want.

switch(menuSelection)
{

case 1:

          {

                   TreeView1.DataSourceID = SiteMapDataSource1.ID;

                   break;

          }

case 2:

          {

                   TreeView1.DataSourceID = SiteMapDataSource2.ID;

                   break;

          }

case 3:

          {

                   TreeView1.DataSourceID = SiteMapDataSource3.ID;

                   break;

          }

default:

          {

                   TreeView1.DataSourceID = SiteMapDataSource1.ID;

                   break;

          }

}

TreeView1.DataBind();

Login to add your contents and source code to this article
share this article :
post comment
 

Will anthoer language take the place of Java? One day ,my teacher asked this question. But we do not know. I am not a scientist,now.

Posted by song kaibo Oct 29, 2007
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor