The problem is that if there is no controller with the expected type name (i.e. if the user types β Amdin β, the ControllerFactory base class will look for the β Amdin controller β and will not find it, but it will still call your overriden method). In this case, the variable controllerType will be zero. That way, you can just check it for null before the line you specified, and then (if it is zero):
A) Make a spelling correction, for example cfeduke suggests
or B) just throw an HttpException with a status code of 404 (this should result in the 404 error you're looking for).
NOTE. If you're doing spelling corrections, you should probably do Response.Redirect to the new URL, and not just silently load the correct controller, so the address bar will change to reflect spelling
source share