【发布时间】:2015-02-12 16:00:33
【问题描述】:
我想使用 ImageController 来提供我的图像:
public class ImageController : Controller
{
// GET: Image
public ActionResult Render(string fileName)
{
byte[] image = System.IO.File.ReadAllBytes(/*some path*/);
return this.Image(image, "image/png");
}
}
我添加了路线:
routes.MapRoute(
name: "Images",
url: "images/{action}/{fileName}",
defaults: new { controller = "Image", action = "Render", fileName = UrlParameter.Optional }
);
所以这个图像路径有效: http://xxx.xxx/images/render/x
但带有此扩展名的路径不会: http://xxx.xxx/images/render/x.png
出现“HTTP 错误 404.0 - 未找到”错误。
我应该怎么做才能启用文件扩展名?
【问题讨论】:
标签: asp.net-mvc routing asp.net-mvc-routing