ninject/Ninject.Web.Mvc

Need to raise 404 for a not found controller in MVC 2.0 code

jbarker7 opened this issue · 3 comments

protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
        if (controllerType == null)
            throw new HttpException(
                404, String.Format(
                         "The controller for path '{0}' could not be found " +
                         "or it does not implement IController.",
                         requestContext.HttpContext.Request.Path));

var controller = Kernel.TryGet(controllerType) as IController;
...

That is the code from DefaultControllerFactory in MVC2 minus the i18n.

What about this in order to preserve base functionality?

if(controllerType == null)
{
// let the base handle 404 errors with proper culture information
return base.GetControllerInstance(requestContext, controllerType);
}

        var controller = Kernel.TryGet(controllerType) as IController;</code>

Yes, much better. Thanks for your help.