maartenba / MvcSiteMapProvider

An ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework.
Microsoft Public License
539 stars 218 forks source link

Handle invalid route / url #374

Closed jentrinanes closed 9 years ago

jentrinanes commented 9 years ago

Is there a way to handle invalid url / route in MvcSiteMapProvider?

I'm getting a "The IControllerFactory 'MvcSiteMapProvider.DI.ControllerFactoryDecorator' did not return a controller for the name 'foo'." error when trying an invalid url. I need to implement a custom 404 error page for this.

NightOwl888 commented 9 years ago

The stack trace is a little misleading. The error is not due to routing, but it is a problem with dependency injection. MvcSiteMapProvider's controller factory only instantiates the type XmlSiteMapController. It wraps the IControllerFactory implementation of the MVC application using a decorator pattern (whether it is the default or a custom one) in order to provide this one special case. So the issue you are having is because the upstream IControllerFactory you have configured is not returning a controller instance when you navigate to that URL, it actually has nothing to do with MvcSiteMapProvider.