0

I'm converting as webforms app to MVC. The previous programmer built a class that inherits the StaticSiteMapProvider class to create his sitemap. He then placed this control on the page

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

and initialized it like this

Dim oSqlSiteMapProvider As New SQL.SiteMap.Provider.SQLSiteMapProvider(Session("KPISystemUserID"), PagePath)
  oSqlSiteMapProvider.Initialize("MySiteMap", Nothing)
  SiteMapDataSource1.Provider = oSqlSiteMapProvider.

He then used the menu control and specified the data source

 <asp:Menu ID="menuMaster" runat="server" DataSourceID="sitemapSQLMenuProvider"/>

I created a class in my MVC project and copied the code over to create the SQLSiteMapProvider class. It created nodes... subnodes.. etc. Is there an easy way with the MvcSiteMapProvider package from Nuget to simply specify this class as where to get the Nodes from? All the documentation just keeps trying to get you to use a static XML file (which i can't use because our menus come from the DB).

It looks like the webform programmer set up his provider like this in the web.config

 <siteMap defaultProvider="KPIMap" enabled="false">
      <providers>
        <clear />
        <add name="KPIMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~/System/MY.sitemap" />
      </providers>
    </siteMap>

and that xml file was simply

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="" title=""  description="">
        <siteMapNode url="" title=""  description="" />
        <siteMapNode url="" title=""  description="" />
    </siteMapNode>
</siteMap>

You'd think they would have added a simple way to plug in the name of a StaticSiteMapProvider class and be done with it.

citronsmurf
  • 90
  • 11
  • Use 1 or more [dynamic node providers](https://stackoverflow.com/a/35632375/) to load the data. – NightOwl888 Jan 19 '18 at 17:14
  • So there's no way to use an existing StaticSiteMapProvider or SiteMapprovider class. I'd have to completely create a brand new class that inherits the IDynamicNodeProvider class and start from scratch? – citronsmurf Jan 19 '18 at 17:20
  • Since `MvcSiteMapProvider` is no longer based on the antiquated `SiteMapProvider` model, you need to convert it. – NightOwl888 Jan 19 '18 at 17:25
  • I didn't realize it was that deprecated. If I was using regular web forms, would there be any better/newer options (hypothetically)? – citronsmurf Jan 19 '18 at 17:40
  • `MvcSiteMapProvider` 3.x used to extend the `StaticSiteMapProvider`, but there were several bugs due to the fact it did not play nicely with MVC. Also, it proved to be very challenging to use dependency injection with a [constrained constructor](http://blog.ploeh.dk/2011/04/27/Providerisnotapattern/) model such as the `StaticSiteMapProvider`. – NightOwl888 Jan 19 '18 at 17:51

0 Answers0