【发布时间】:2011-06-14 23:16:33
【问题描述】:
我有一个看起来像这样的视图 {{img src="/Scenario/Status/id" alt="status" /}}
(替换上面的这些{})
这是控制器的代码
public ActionResult Status(int? id)
{
// Calculate the status
int no = new Random().Next(0, 2);
string file = "green.jpg";
if (no == 0)
{
file = "red.jpg";
}
else if (no == 1)
{
file = "yellow.jpg";
}
else if (no == 2)
{
file = "green.jpg";
}
var path = Server.MapPath("/Content/images/");
var filePath = path + file;
return new FileContentResult(System.IO.File.ReadAllBytes(filePath), "image/jpeg");
}
当我在 visualstudio 上运行时,这工作得很好。但是当我将它部署到本地 IIS 时,我看不到这些图像。 我检查了在 IIS 下的 Windows 功能中检查了“StaticContent”选项,并且在 IIS 上启用了 MIME 类型。从 Visual Studio 发布后,我还检查了 *.jpg 文件是否存在于我的应用程序的“inetpub”文件夹下。由于我使用图像的虚拟路径而不是硬压缩文件名,它应该可以工作......
我刚试过这个
{{img src="../Content/Images/Green.jpg" alt="status" /}} 这也有效.. :(
还有什么问题?
【问题讨论】:
-
部署到 IIS 时是部署到虚拟目录还是站点根目录?
标签: asp.net-mvc