0

我正在尝试将诸如图像之类的文件从子文件夹路由到根目录,但不知道要这样做。我还检查了网络上的一些脚本,但这些都不起作用。

Source: /Projects/test/images/img.jpg
Destination: /images/img.jpg

我会很感激你的帮助。

4

2 回答 2

2

尝试这样的事情:

路线:

routes.MapRoute("Image", "Images/{file}",
                 new { controller = "Images", action = "Images" }
);

控制器:

public ActionResult Images(string file)
{
    path = "/Projects/test/images/" + file;
    if (!System.IO.File.Exists(path))
    {
        return new HttpNotFoundResult();
    }

    return File(path, "image/jpeg");
}
于 2013-06-03T06:54:13.013 回答
1

为此使用 URL 重写规则。

于 2013-06-03T06:18:39.743 回答