Shouldn't MVC ignore images by default?

别说谁变了你拦得住时间么 提交于 2019-12-30 10:52:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!