I have this as my DefaultControllerFactory override:
public class StructureMapControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, System.Type controllerType)
{
if (controllerType == null) return base.GetControllerInstance(requestContext, controllerType);
return (IController)ObjectFactory.GetInstance(controllerType);
}
}
My Global.asax looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("favicon.ico");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"404-PageNotFound",
"{*url}",
new { controller = "ErrorController", action = "PageNotFound" }
);
}
When I go to mydomain.com/asd/asd/asd/asd/asd/asd it throws a 404 exception and then looks in the customErrors node in the web.config to decide what to do.
I’m not sure whether this is right or not because I would have thought my routes would have handled this and not the customErrors.
I think that problem is in “404-PageNotFound” route declaration. If you want this to be handled by ErrorController, you should specify “Error” as route value, not “ErrorController”, as asp.net mvc controller naming convention states. In your case, probably asp.net default 404 error is rendered because it cannot navigate to “ErrorController”