Uğur UMUTLUOĞLU
Web Technologies, Microsoft and .NET Technologies

Using More Than One Sitemap File in ASP.NET Applications

Wednesday, 6 May 2009 23:14 by ugur
When we use navigation controls with SiteMapDataSource in ASP.NET applications, we can use only one sitemap file. The reason of this situation is that, the web.config file included in the directory in which .NET Framework is installed that is used as an inheritance by web.config file in the applications has only one SiteMap provider definition. If you look <siteMap> nodule included in web.config file in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG directory in a computer in which .NET Framework 2.0 has been installed, you can see only one provider defined and there is web.sitemap file name that has siteMapFile attribution. Actually, we can solve how to use more than one sitemap file starting in here. If we want to add second sitemap file to our application and use it with navigation controls, firstly we should make a new sitemap provider definition in the web.config file of our application. You can see the code snippet that will be added to <system.web> nodule in web.config file below.

web.config
<
system.web>

    ...

    <siteMap>

        <providers>

            <add name="SiteMapProvider2" siteMapFile="web2.sitemap" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

        </providers>

    </siteMap>

</system.web>

We defined a new siteMap provider named SiteMapProvider2 that will work with web2.sitemap file. We can now use another sitemap file named web2.sitemap beside the web.sitemap file in this application. We are testing the use of more than one sitemap file by adding two Menu controls and two SiteMapDataSource controls to the ASP.NET page. The point that must be paid attention in here is equaling the SiteMapProvider property of SiteMapDataSource control that will be connect to web2.sitemap file to the SiteMapProvider2 defined in web.config.

 

Default.aspx

<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1"></asp:Menu>

<br />

<asp:Menu ID="Menu2" runat="server" DataSourceID="SiteMapDataSource2"></asp:Menu>

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />

<asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" ShowStartingNode="False" SiteMapProvider="SiteMapProvider2" />

Tags:   ,
Categories:   ASP.NET
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed
 
Add to Technorati Favorites