Changing SiteMap File name

Changing SiteMap File name


The navigation system introduced in ASP.NET 2.0 allows developers to store the entire website structure in an XML file called sitemap. By default the site navigation system works with the sitemap file named Web.sitemap. What if you want to change the file name to something else say Site.sitemap?
This article will describe how to make your navigation system work with a sitemap file named other than Web.sitemap. If you change your sitemap file name, you will get the following exception:
System.InvalidOperationException: The file web.sitemap required by XmlSiteMapProvider does not exist.

Open your web application root web.config file and add the following code to your web.config in <system.web> element

<siteMap defaultProvider="CustomXmlSiteMapProvider" >

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

</siteMap>


The above code registers a XMLSiteMapProvider named CustomXMLSiteMapProvider. You can choose any name for provider you want. siteMapFile attribute specifies the name of the file that provider will use to load navigation data. You will set this attribute's value to the name of your Sitemap file. In the above mentioned code I have set it to site.sitemap which means I can use the sitemap file named Site.sitemap.


defaultProvider attribute of the siteMap element is essential because it sets the default sitemap provider for application. If this attribute is not included the application will continue using the default AspNetXMLSiteMapProvider which is registered in the Framework's web.config and uses the Web.sitemap file.

Hope this helps
Mohsin


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: