asp.net mvc 4 - How to configure multiple sitemaps using MVCSiteMapProvider v4 with StructureMap DI -
the problem, essentially, can't sitemap config support multiple sitemaps. it's looking "default" when name instances , request another. background.
i've been pouring on docs new implementation of mvcsitemapprovider. using dependency injection configure sitemapprovider. have existing structuremap di implementation, followed instructions , added, in our case
objectfactory.configure(x => { ... x.addregistry<mvcsitemapproviderregistry>(); ... });
then started tweaking mvcsitemapproviderregistry.cs file implement multiple sitemap scenario. have multiple site map files, either work long it's called "default". if remove "default" item breaks , complains "default" missing. assume because can't find instance. here's how have them defined. suspect problem somewhere in here... loader says have configure in global.asax looking isitemaploader i'm adding multiple configuration sitemapbuilderset... anyway here's code.
// register sitemap builder string absolutefilename = hostingenvironment.mappath("~/main.sitemap"); string absolutefilename2 = hostingenvironment.mappath("~/test.sitemap"); var xmlsource = this.for<ixmlsource>().use<filexmlsource>() .ctor<string>("filename").is(absolutefilename); var reservedattributenameprovider = this.for<isitemapxmlreservedattributenameprovider>() .use<sitemapxmlreservedattributenameprovider>() .ctor<ienumerable<string>>("attributestoignore").is(new string[0]); var builder = this.for<isitemapbuilder>().use<compositesitemapbuilder>() .enumerableof<isitemapbuilder>().contains(y => { y.type<xmlsitemapbuilder>() .ctor<isitemapxmlreservedattributenameprovider>().is(reservedattributenameprovider) .ctor<ixmlsource>().is(xmlsource); y.type<reflectionsitemapbuilder>() .ctor<ienumerable<string>>("includeassemblies").is(includeassembliesforscan) .ctor<ienumerable<string>>("excludeassemblies").is(new string[0]); y.type<visitingsitemapbuilder>(); }); var xmlsource2 = this.for<ixmlsource>().use<filexmlsource>() .ctor<string>("filename").is(absolutefilename2); var builder2 = this.for<isitemapbuilder>().use<compositesitemapbuilder>() .enumerableof<isitemapbuilder>().contains(y => { y.type<xmlsitemapbuilder>() .ctor<isitemapxmlreservedattributenameprovider>().is(reservedattributenameprovider) .ctor<ixmlsource>().is(xmlsource2); y.type<reflectionsitemapbuilder>() .ctor<ienumerable<string>>("includeassemblies").is(includeassembliesforscan) .ctor<ienumerable<string>>("excludeassemblies").is(new string[0]); y.type<visitingsitemapbuilder>(); }); // configure builder sets this.for<isitemapbuildersetstrategy>().use<sitemapbuildersetstrategy>() .enumerableof<isitemapbuilderset>().contains(x => { /* x.type<sitemapbuilderset>() .ctor<string>("instancename").is("default") .ctor<bool>("securitytrimmingenabled").is(securitytrimmingenabled) .ctor<bool>("enablelocalization").is(enablelocalization) .ctor<isitemapbuilder>().is(builder) .ctor<icachedetails>().is(cachedetails);*/ /* x.type<sitemapbuilderset>() .ctor<string>("instancename").is("mainsitemapprovider") .ctor<bool>("securitytrimmingenabled").is(securitytrimmingenabled) .ctor<bool>("enablelocalization").is(enablelocalization) .ctor<isitemapbuilder>().is(builder) .ctor<icachedetails>().is(cachedetails);*/ x.type<sitemapbuilderset>() .ctor<string>("instancename").is("testsitemapprovider") .ctor<bool>("securitytrimmingenabled").is(securitytrimmingenabled) .ctor<bool>("enablelocalization").is(enablelocalization) .ctor<isitemapbuilder>().is(builder2) .ctor<icachedetails>().is(cachedetails); });
in global.asax.cs added
mvcsitemapprovider.sitemaps.loader = resolver.get<isitemaploader>();
and reference in view have
@html.mvcsitemap("testsitemapprovider").menu(false, true, true)
but must not able find "testsitemapprovider" because displays "default" or complains if doesn't exist.
i thought might have cache, see filename referenced there, don't know how add multiple instances cache, disabled it. i'm not doing fancy sitemaps anyway, , whole thing feeling massive overkill flippin automatic breadcrumbs!
apparently there doc wasn't aware of. had completed of steps far properly, needed implement isitemapcachekeygenerator.
see doc (which wasn't named when started.) https://github.com/maartenba/mvcsitemapprovider/wiki/multiple-sitemaps-in-one-application
Comments
Post a Comment