MvcSiteMapProvider store all nodes in database

848 views Asked by At

Now i have Mvc.sitemap xml file with following data:

<mvcSiteMapNode title="RTS" imageUrl="fa fa-share-alt" controller="Dashboard" action="Index" area="Referrals" >
  <mvcSiteMapNode title="Dashboard" controller="Dashboard" action="Index" area="Referrals" ></mvcSiteMapNode>

  <mvcSiteMapNode title="Referrals" controller="List" action="Index" area="Referrals" visibility="SiteMapPathHelper,!*">
    <mvcSiteMapNode title="New Referral" controller="List" action="New" area="Referrals" visibility="SiteMapPathHelper,!*" preservedRouteParameters="id" />
    <mvcSiteMapNode title="Details" controller="List" action="Details" area="Referrals" visibility="SiteMapPathHelper,!*" preservedRouteParameters="id" >
      <mvcSiteMapNode title="Edit" action="Edit" area="Referrals" visibility="SiteMapPathHelper,!*" preservedRouteParameters="id"/>
    </mvcSiteMapNode>
  </mvcSiteMapNode>

</mvcSiteMapNode>

And i want to store all this nodes in DB, and have just one not root node, like this:

<mvcSiteMapNode visibility="MenuHelper,!*" title="Home" controller="Home" action="Index"  imageUrl="fa fa-home">
    <mvcSiteMapNode visibility="MenuHelper,!*" title="Home" controller="Home" action="Index"  imageUrl="fa fa-home" dynamicNodeProvider="RMP.WebClient.Infrastructure.SiteMapDynamicNodeProvider, RMP.WebClient">
    </mvcSiteMapNode>
  </mvcSiteMapNode>

Can i do this using DynamicNodeProvider or what the best way to implement this logic?

1

There are 1 answers

0
NightOwl888 On BEST ANSWER

Yes, you can use a single dynamic node provider to supply all nodes if that is what you prefer. You just need to ensure that you map all of the key and parent key properties correctly. This is your best bet if you are using internal DI.

If using external DI, there is a better option. You could implement ISiteMapNodeProvider, and then you wouldn't need an XML file (or .NET attribute) at all to host your root node. ISiteMapNodeProvider is implemented in a similar way as IDyanmicNodeProvider, the primary difference is that it operates at a lower level and requires external DI to inject the implementation. See this answer for a sample ISiteMapNodeProvider implementation and this answer to see how you might inject your implementation. You only need to inject the built-in XmlSiteMapNodeProvider if you intend to use XML for node configuration and the ReflectionSiteMapNodeProvider if you intend to use [MvcSiteMapNodeAttribute] for node configuration.

Note that in future versions of MvcSiteMapProvider, you will be able to use ISiteMapNodeProvider without an external DI container.