Need to raise 404 for a not found controller in MVC 2.0 code
jbarker7 opened this issue · 3 comments
jbarker7 commented
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;
...
idavis commented
That is the code from DefaultControllerFactory in MVC2 minus the i18n.
idavis commented
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>
jbarker7 commented
Yes, much better. Thanks for your help.