asp.net - 显示存储在 App_Data 中的图像

标签 asp.net asp.net-mvc image asp.net-mvc-4 app-data

我的 App_Data 目录中有 2 个图像文件,我想在我的 View 中显示它们,如下所示:

@foreach (var media in Model)
{
     <div class="col-lg-3 col-md-4 col-xs-6 thumb">
         <a class="thumbnail"><img src="@Url.Content("~/App_Data/uploads/" + @media.URL)" alt="image" /></a>
      </div>
}

当我检查浏览器中的链接时,我得到了这个:
<img src="/App_Data/uploads/Warnings.png" alt="image">

它说他找不到图像。如何设置正确的链接?

最佳答案

App_Data 文件夹是一个特殊的 .NET“系统”文件夹,其中 IIS 被配置为不允许 Web 用户看到该文件夹​​的内容。创建一个不同的文件夹来存储您的图像,因为您确实不应该允许 App_Data 在网络上可见(如果您甚至可以更改设置)。

From iis.net :

For example, on Web servers that are hosting ASP.NET content, IIS 7 blocks several of the ASP.NET-related paths for you; Web.config, bin, App_Code, etc. Blocking these URL segments reduce the chance of an attacker being able to exploit these URLs for information.

关于asp.net - 显示存储在 App_Data 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20688022/

相关文章:

internet-explorer - 此页面的状态信息无效,可能已损坏

angularjs - ng-src 用于本地镜像

javascript - asp.net mvc - 将 javascript 类传递给 POST 请求

html - CSS 不会在服务器上加载图像

image - 如何将原始数据存储在图像文件中?

Asp.net 身份注销其他用户

asp.net - 尝试创建角色时,列名区分符无效

C# - 从 "cast"List<BaseClass> 到 List<DerivedClass> 的简单方法?

asp.net-mvc - 如何返回 OPENXML Word 文档的 MVC ActionResult?

html - 如何使用 Html.BeginForm 打开新窗口