【发布时间】:2016-04-11 17:00:40
【问题描述】:
我的视图中有 img 标签,如下所示
<img src="@Url.Action("Images", "MemberImage", new { image = TempData["id"]+".jpg" }) "
alt=" " style="width: 100px;height:150px" />
我的控制器是
public ActionResult Images(string image)
{
var root = @"\\server1\PHOTOGRAPHS received\photos";
var path = Path.Combine(root, image);
path = Path.GetFullPath(path);
if (!path.StartsWith(root))
{
// Ensure that we are serving file only inside the root folder
// and block requests outside like "../web.config"
throw new HttpException(403, "Forbidden");
}
return File(path, "image/jpeg");
}
这在我的本地系统中运行良好,但是当我部署到 IIS 时,图片没有显示。 安装 IIS 的服务器可以访问此路径 我还需要做其他配置吗?
【问题讨论】:
-
当您浏览到图像时,您会得到什么状态码,404、500 或其他?网站上的其他页面是否正常工作(例如纯 HTML 页面)
-
@NikolaiDante 页面正在加载其他详细信息。需要加载图像的区域是小矩形。当我检查元素时,它显示
src="Client/MemberImage/Images/12345.jpg"并给出消息图像无法加载。 -
如果您导航到 www.yoursite.com/Client/MemberImage/Images/12345.jpg 会发生什么?客户端是 IIS 服务器上的虚拟目录吗?
标签: asp.net-mvc iis iis-7