I have created an ImageController to serve images from a location in my project. Now I'm trying to get it to route from "/Image/file.png" to my Controller, but I can't seem to get it right. The controller is never been called (I set a breakpoint in the first line of the action and it never breaks).
My route:
routes.MapRoute(
"Image",
"Image/{file}",
new { controller = "Image", action = "Render", file = "" }
);
My ImageController:
public class ImageController : Controller
{
//
// GET: /Image/
public ActionResult Render(string file)
{
var path = this.getPath(file);
System.Diagnostics.Debug.WriteLine(path);
if (!System.IO.File.Exists(path))
{
return new HttpNotFoundResult(string.Format("File {0} not found.", path));
}
return new ImageResult(path);
}
private string getPath(string file)
{
return string.Format("{0}/{1}", Server.MapPath("~/Content/Images"), file);
}
}
Why isn't my project routing from "Images/{file}" to my controller?