Search code examples
c#asp.netasp.net-mvcmvcsitemapprovider

MvcSiteMapProvider - modify node url


I have a distributed mvc asp.net web application. The application's UI is split across different components, and each component has a different host value, meaning that the application has different URLs for different portions of the UI. There is a single XML sitemap file that is shared across the different components. The nodes in the sitemap use relative URLs and an attribute indicating what host value should be used and the host value is stored in a configuration file - this is because the application exists in a few different environments and as such hardcoding a fully qualified URL in the sitemap would not be practical.

Given all of that, when a sitemap node is rendered in some navigational link, I must modify the node's URL to make it fully qualified using the correct host. I can do this rather easily with the .net SiteMapNode class.

My problem is that I need to do something similar with MvcSiteMapProvider. I haven't had much luck so far. Suggestions welcome.


Solution

  • I'm trying the approach discussed here, namely using a custom ISiteMapNodeUrlResolver.

    The default implementation already replaces the host name with an optionally supplied hostName attribute in an xml sitemap file. In my custom implementation, I looked up a configuration setting based on the hostName attribute to arrive at a runtime modification based on a configuration setting.

    So far, it seems to be working as needed.