I have an MVC 5 application with Unity DI using the MvcSiteMapProvider
package from NuGet. I'm trying to use the ignore MvcSiteMapProvider_AttributesToIgnore
appSetting in my web.config
file like the following
<add key="MvcSiteMapProvider_AttributesToIgnore" value="type" />
But when my sitemap is displayed, the urls have the ignored value as the querystring.
There is a section in the MvcSiteMapProvider
documentation that reads
If using an external DI container, this setting can be found on the constructor of the ReservedAttributeNameProvider in a parameter named "attributesToIgnore", which is type IEnumerable
I'm using Unity so I wonder if I need to add this to my container somehow, but I don't know how.
Any ideas on how to ignore route values?
You just need to add the settings to the ReservedAttributeNameProvider as described in the documentation:
// Prepare for the sitemap node providers
this.Container.RegisterType<IXmlSource, FileXmlSource>("file1XmlSource", new InjectionConstructor(absoluteFileName));
this.Container.RegisterType<IReservedAttributeNameProvider, ReservedAttributeNameProvider>(
// Add the attributes to ignore here
new InjectionConstructor(new string[] { "type", "value2" }));
Tip: You can always find out what dependencies a class has by temporarily newing up the class and looking at the parameters with Intellisense.
new ReservedAttributeNameProvider(
// Type the above in Visual Studio and you will see the constructor parameters
// in a tooltip