Asp.Net Mvc 5图像未显示 [英] Asp.Net Mvc 5 image not displaying

查看:77
本文介绍了Asp.Net Mvc 5图像未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Content Views 文件夹中具有相同的图像.我正在尝试显示如下图像:

I have same images in Content and Views folders. I am trying to display images as below:

<img src="~/Content/Images/download.png" alt="Content folder" />
<br />
<br />
<img src="~/Views/Home/download.png" alt="Views folder" />
<br />

Content 文件夹中的图像显示成功,但Views文件夹中的图像未显示,并显示以下错误:

The image in Content folder displays successfully but the one in Views folder doesn't display and gives below error:

无法加载资源:服务器响应状态为404(未找到)

Failed to load resource: the server responded with a status of 404 (Not Found)

但是实际上,资源在那里.这是我的文件夹:

But actually, the resource is there. Here are my folders:

您能告诉我我做错了什么吗?我正在将MVC 5与剃须刀引擎和Visual Studio 2015社区版一起使用.

Could you please tell me which point I am doing wrong? I am using MVC 5 with razor engine and Visual Studio 2015 community edition.

推荐答案

除非更改了默认配置,否则文件夹 Views 包含文件 Web.config ,该文件具有限制设置访问此文件夹中的文件:

Unless you changed the default configuration, folder Views contains file Web.config that has settings for restricting access to files in this folder:

<system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" 
           type="System.Web.HttpNotFoundHandler" />
    </handlers>
</system.webServer>

因此,您可以删除此处理程序(出于安全目的不建议使用此处理程序),也可以将静态文件移动到其他文件夹中,例如内容.

So you can either remove this handler (which is not recommended for security purposes), or move your static files to some other folder, e.g. Content.

这篇关于Asp.Net Mvc 5图像未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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