D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

Using Multiple Sitemap Files

Thursday, October 4, 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

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

# 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

# re: Using Multiple Sitemap Files

Huge thanks ! It was all that I was looking for. Simple and straight to the point. msdn really is shit, always getting around the answer. 12/10/2008 8:09 AM | gheorghe

# re: Using Multiple Sitemap Files

Thanks, this helped me a lot!! 1/15/2009 8:03 AM | Tatolo

# re: Using Multiple Sitemap Files

Much obliged! 2/25/2009 9:41 AM | GL

# re: Using Multiple Sitemap Files

Thank you very much, you rock man 3/18/2009 2:33 PM | Nikhil

# re: Using Multiple Sitemap Files

Very simple, and very helpfull.
thanks a lot
4/25/2009 10:57 AM | abdel

# re: Using Multiple Sitemap Files

thanks a lot its really so simple to use 7/21/2009 1:01 AM | priyanka

# re: Using Multiple Sitemap Files

D,Arcy,

Very nice and simple article. Just one addition though. If you don't add the original Sitemap as a default in the SiteMap tag other pages will use this new tag as the default as well.

<siteMap enabled="true" defaultProvider="Web.sitemap">

Remember the changes are are only visible at runtime.

Great work: 8/22/2009 8:32 AM | Everel Morris Broadridge NY

# Thanks

Thank you for this article.
It was useful to me. 8/23/2009 7:09 AM | Mohammad Hussein

# re: Using Multiple Sitemap Files

Thank you very much, very helpful article

Best regards 9/8/2009 9:04 PM | Nurken

# re: Using Multiple Sitemap Files

after adding the code to me application i am facing the same problem like seeing the default sitemap. i added the code in web.cofig between this tags <system.web></system.web> and named as homesitemap
see my code
<asp:sitemapdatasource id="mainsmdsmaste" runat="server" sitemapprovider="Homesitemap"/>
<asp:Menu id="NewMenuId" runtat="server" datasorceid="mainsmdsmaste">
Can any one plz help me to reo
10/1/2009 12:59 AM | Balakrishna

# re: Using Multiple Sitemap Files

Is there a way to change the siteMapProvider dynamically depending on the subdirectory of the page being viewed? For instance, I have sitemaps set up in a few subdirectories and I would like the siteMapDataSource in my master page to change provider names depending on the location. 10/6/2009 11:10 AM | Tony

# re: Using Multiple Sitemap Files

GREAT! You're the bbbeeeeeeeeeeeessssssttttttt! 10/14/2009 8:53 AM | Robert Green

# re: Using Multiple Sitemap Files

Thanks a LLLLLLOOOOOOOOTTTTTTTTTTT..........
It works!!!!!!!! 12/15/2009 2:33 AM | Surena

# re: Using Multiple Sitemap Files

thanks it was really very helpful 1/18/2010 1:08 AM | Sami

# re: Using Multiple Sitemap Files

Many thanks. Clear and concise - unlike the confusing MSDN support file. Resolved the issue first time! 2/3/2010 3:55 PM | Deane

# re: Using Multiple Sitemap Files

For once read a short and complete description is a pleasure. 5/5/2010 3:13 AM | Christer

# re: Using Multiple Sitemap Files

I added the above lines to web.config and get this error
"Error 150 Sections must only appear once per config file. " 8/5/2010 2:46 AM | RT

# re: Using Multiple Sitemap Files

This code helped me, thanks! \(^-^)/
hello RT, maybe you have two <siteMap>.. </siteMap> in your web.config.
Hey this link is also useful:
http://itechtalk.wordpress.com/2007/12/07/configuring-multiple-sitemaps-in-net/ 8/12/2010 6:38 AM | meiaowsh

# re: Using Multiple Sitemap Files

Great..! this trick crak my problem. 9/1/2010 2:32 AM | Sagar

# re: Using Multiple Sitemap Files

Thanks! This code helped me out a bunch! 10/18/2010 10:54 AM | Grady Christie

# re: Using Multiple Sitemap Files

FANTASTIC!!

Just remember to add it to the web.config bit! Great stuff, solved my problem in seconds. love it! 3/3/2011 6:47 PM | anon

# re: Using Multiple Sitemap Files

Hi All

I still encounter the same problem. my datasource2 still read from the default. Any idea?

3/27/2011 4:42 AM | Benjamin

# re: Using Multiple Sitemap Files

Thankyou! Clear and to the point! if only the rest of the documentation was as good and clear :) 5/7/2011 1:18 AM | Anna Tito

# re: Using Multiple Sitemap Files

Quite useful
Thanks 7/5/2011 3:59 AM | Zaki

# re: Using Multiple Sitemap Files

What does markup means in this code what i mean is where does this markup is


Then in the markup for your SiteMapDataSource, just add the line to its tag:
SiteMapProvider="MyNewSitemapProvider" 9/9/2011 1:01 PM | korivi pramod

# re: Using Multiple Sitemap Files

Excellent... thanks a lot for posting this. 9/13/2011 9:10 AM | Nitin

# re: Using Multiple Sitemap Files

Awesome! Needed this! 9/22/2011 8:30 AM | Villan

# re: Using Multiple Sitemap Files

Thanks :)
Very helpful. 11/30/2011 12:39 AM | Chundunsing

# re: Using Multiple Sitemap Files

thanx :-) 3/26/2012 11:53 PM | hkumar

# re: Using Multiple Sitemap Files

Excellent.....
Exactly what I was looking for.
Thank you very much. 5/8/2012 5:23 AM | sohrab

# re: Using Multiple Sitemap Files

i used ur code in web.config file, but it still showing me an error...
<siteMap enable="true">
Line 76: <providers>
Line 77: <add name="MyNewSitemapProvider"


Can u plz help me to work out this.. 5/10/2012 7:05 AM | chitra

# re: Using Multiple Sitemap Files

Really nice and easy. 5/11/2012 3:44 AM | Gaurav

# re: Using Multiple Sitemap Files

that was great and it works fine!!! 12/16/2012 2:03 AM | ravirosn

# re: Using Multiple Sitemap Files

Thank You. I was looking for the simple answer, and this is it. Works great! 5/21/2013 1:57 PM | Bill Kuhn

# re: Using Multiple Sitemap Files

Hello, I am using 2 sitemap but i am still see first sitemap.

i am having problem 5/27/2015 7:06 AM | santosh

# re: Using Multiple Sitemap Files

Thankyou! Clear and to the point! if only the rest of the documentation was as good and clear free itune gift code generator 11/28/2017 4:46 AM | kesar

Post a comment