MvcSiteMapProvider saves all nodes in the database

Now I have an Mvc.sitemap xml file with the 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 keep all these nodes in the DB and only have one non-root node, for example:

<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 with DynamicNodeProvider or what is the best way to implement this logic?

+3


source to share


1 answer


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

When using an external DI, it is best to choose the option. You can implement ISiteMapNodeProvider and then you don't need an XML file (or .NET attribute) to host your root node. ISiteMapNodeProvider is implemented similarly to IDyanmicNodeProvider, the main difference is that it operates at a lower level and requires an external DI to inject the implementation. See this answer for an example implementation of ISiteMapNodeProvider and this answer for how you might add your implementation. You only need to inject the built-in XmlSiteMapNodeProvider if you intend to use XML for the node configuration and ReflectionSiteMapNodeProvider if you intend to use the [MvcSiteMapNodeAttribute] configuration for the node configuration.



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

+1


source







All Articles