can IIS actually know if a request in asp.net MVC is a 404 because it might
or it might not me mapped via any route?
I think it all depends on how your controller factory handles the unmapped request. The DefaultController factory seems to throw an HttpException with code 404 when it cannot find a route and let IIS handle the error display. You can play with this and see it in action by creating your own controller factory.
For example, add the following line to your Application_Start
ControllerBuilder.Current.SetControllerFactory(new TestControllerFactory());
and add this class to a brand new MVC project:
public class TestControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
{
//throw new Exception("Oops!"); // yellow screen of death
throw new System.Web.HttpException(404, "Oops not found!"); // bubbles up to IIS
}
return base.GetControllerInstance(requestContext, controllerType);
}
}
Navigate to your project to http://localhost/MvcApplication1/unmapped and see what happens when you throw an HttpException with code 404 versus when you throw a regular Exception (or even an HttpException with a code other than 404)
Make sure you are running your project under IIS (rather than the VS Dev Server) as the they handle these things different.