不应该忽视MVC默认图像? [英] Shouldn't MVC ignore images by default?

查看:114
本文介绍了不应该忽视MVC默认图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有 1.JPG 图像,因此被下载和显示

 < IMG SRC =内容/页/ 1.JPG/>

但是,如果在信息页文件夹中没有 1.JPG 的形象,所以我得到了以下错误

 的路径/Content/Pages/1.jpg控制器无法找到或没有实现一个IController。

我固定它通过注册路线 IgnoreRoute ,但不应默认情况下它忽略图像?

  routes.IgnoreRoute(内容/ {*} PATHINFO);


解决方案

这实际上是由您的主机环境/ WEB服务器处理,而不是由每本身MVC。

我怀疑你是在开发过程中使用Visual Studio的Web服务器,对不对? Visual Studio的Web服务器不能处理默认情况下,这些请求。

如果你的主机与IIS项目,IIS将照顾这。 IIS将拦截请求的JPG和处理它,而不是让打你的code。但是,Visual Studio的Web服务器不。

这并不少见有你提到的,因为很多人在VS Web服务器开发忽略路线。

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}"); 

解决方案

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.

这篇关于不应该忽视MVC默认图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆