我的 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/