问题
If there is 1.jpg
image, so it is downloaded and showed
<img src="Content/Pages/1.jpg" />
But, if there is no 1.jpg
image in Pages folder, so I get the following error
The controller for path '/Content/Pages/1.jpg' could not be found or it does not implement IController.
I fixed it by registering route to IgnoreRoute
, but shouldn't it ignore images by default?
routes.IgnoreRoute("Content/{*pathInfo}");
回答1:
That's actually handled by your hosting environment/web server, not by MVC per-se.
I suspect you are using the Visual Studio Web Server during development, right? The Visual Studio Web Server does not handle these requests by default.
If you host your project with IIS, IIS will take care of this. IIS will intercept the request to a JPG and handle it rather than letting hit your code. But the Visual Studio Web Server does not.
It's not uncommon to have the ignore route that you mentioned because a lot of people develop with the VS Web Server.
来源:https://stackoverflow.com/questions/7333343/shouldnt-mvc-ignore-images-by-default