D'Arcy from Winnipeg
Musings of a Canadian BizTalk and SOA Developer

Using Multiple Sitemap Files

Thursday, October 04, 2007 4:07 AM

By default, ASP.NET comes with a default SiteMap provider which expects a file called Web.sitemap to be in your project. This is great if you only want one file, but what if you want multiple sitemap files? Implementing this functionality is pretty easy:

Add the below code to your web.config file within the System.Web tag. This creates a new "provider" that you can specify for a SiteMapDataSource control to tell it to look for a different sitemap file.

 <siteMap enabled="true">
     <
providers>
             <
add name="MyNewSitemapProvider"
                    
type="System.Web.XmlSiteMapProvider"
                    
siteMapFile="MyNewSitemapFile.sitemap"/>
    
</providers>
</
siteMap>

Then in the markup for your SiteMapDataSource, just add the line to its tag:

SiteMapProvider="MyNewSitemapProvider"

This tells it to use the new provider instead of the default one.

Then just set your menu or other navigation control to point to the new SiteMapDataSource for its datasource and all should be good! You can also have as many providers listed as you want...so if you have 5 different maps that you want to make available, just add away!

D


Feedback

# re: Using Multiple Sitemap Files

Thank you very much. The code was simple and got to the point. I tried Microsoft's MSDN crap and the examples were horrible.

Thank you again. I've saved this website in my bookmarks.

Dave 10/18/2007 6:44 PM | Dave

# re: Using Multiple Sitemap Files

Ahhh. Exactly what I was looking for... Thank you! 10/26/2007 8:02 PM | Boid

# re: Using Multiple Sitemap Files

Thanks a lot. That is simple but really helpful! 12/5/2007 2:02 PM | thuanlee_tma

# re: Using Multiple Sitemap Files

Excellent.

MSDN uses a few pages on the topic and is difficult to understand. I do not know if it works. I got lost anyway.

The one in Code project is relatively easily to understand but it does not seem to work (the menu using the sitemap just disappears at run time). It involves creating the sitemaps, a class, a custom control for the menu. Then add the menu control and sets it properties.

Yours is simple and works

Many Thanks 1/4/2008 1:26 AM | T C

# re: Using Multiple Sitemap Files

Thanks a lot. How simple. Why couldn't I find this information on MSDN. 2/19/2008 2:08 PM | FlorisV

# re: Using Multiple Sitemap Files

Easy to understand unlike everything else I've tried to find out using this software.

Cheers 3/22/2008 5:44 AM | Paul

# re: Using Multiple Sitemap Files

straight to the point! thank you great work :) 4/7/2008 7:07 AM | mike

# re: Using Multiple Sitemap Files

you got this working when msdn couldn't!! thanks for the simple directions! 5/6/2008 2:40 PM | caroline

# re: Using Multiple Sitemap Files

Perfect... Thanks! 5/31/2008 5:29 PM | kevin

# re: Using Multiple Sitemap Files

Great job.... Beter than MSDN ... Thanks a lot... 6/8/2008 9:28 AM | ujjawal

# re: Using Multiple Sitemap Files

EXCELLENT !!! THX for sharing !
screw MSDN ^%^#$%&... 6/20/2008 6:31 AM | y2kstephen

# re: Using Multiple Sitemap Files

I tried this, but it gave me following error, can you please help?
Error 36 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Thank you,
Sandhya. 6/22/2008 4:18 PM | sandhya

# re: Using Multiple Sitemap Files

Exactly what I needed!!! Great job and thanks for taking the time to share this information. 6/23/2008 10:18 AM | TheDirtyBird

# re: Using Multiple Sitemap Files

Thanks man.. 7/7/2008 11:02 AM | Dwain browne

# re: Using Multiple Sitemap Files

thanks, way easier. 8/20/2008 10:40 AM | jshapaka

# Superb!

Thank you. This little tip saved me hours of work. 9/12/2008 1:30 PM | Hamed

# re: Using Multiple Sitemap Files

Thanks heaps! I'm new to asp.net and love it. Being shown code like this that's easy to understand add to my enjoyment!!! 11/11/2008 4:44 AM | Ben K

Post a comment





 

Please add 2 and 6 and type the answer here: