How to use multiple .sitemap files in ASP.NET
Asked Answered
P

1

5

I think I'm missing something obvious about sitemaps.

I'm trying to use a repeater to generate some navigation for a new sitemap we have on our site. But I don't want to use our normal Web.sitemap file, I want to use our new one...we'll call it "Web.NEW.sitemap".

The code seems somewhat obvious to a point...

<asp:Repeater ID="rptMyRepeater" DataSourceID="mySitemap" runat="server">
    <ItemTemplate>
        blah blah blah
    </ItemTemplate>
</asp:Repeater>

<asp:SiteMapDataSource ID="mySitemap" runat="server" />

But how do I get SiteMapDataSource to use Web.NEW.sitemap instead of the default sitemap? I thought adding an attribute like:

SiteMapProvider="Web.NEW.sitemap"

ought to do it, but no dice.

What am I missing?

Poussin answered 27/5, 2009 at 16:18 Comment(0)
D
10

You have to configure your web.config properly to make use of the SiteMapDataSource property. Use the SiteMap element:

<siteMap defaultProvider="oldProvider">
  <providers>
    <clear />
    <add name="oldProvider" type="System.Web.XmlSiteMapProvider" siteMapFile="web.sitemap" />
    <add name="newProvider" type="System.Web.XmlSiteMapProvider" siteMapFile="Web.NEW.sitemap" />
  </providers>
</siteMap>

and then set the SiteMapProvider property to the provider's name from the web.config file.

SiteMapProvider="newProvider"
Denudate answered 27/5, 2009 at 16:34 Comment(2)
@NKhan, I set the SiteMapProvider in my CodeBehind file, so after setting the SiteMapProvider, I had to DataBind() my SiteMap and then my Menu (which I was using the SiteMap for): _siteMap.SiteMapProvider = "newProvider"; _siteMap.DataBind(); _menu.DataBind(); Do you need to do this? Does this work for you?Kylynn
I don't know how to get the formatting to work properly, but those are three separate commands that I wanted on three separate lines.Kylynn

© 2022 - 2024 — McMap. All rights reserved.