Reputation: 462
i'm trying to route files like images from subfolder to root but don't have any idea to do this. Also i've checked some scripts around the web, but nothing of these would work.
Source: /Projects/test/images/img.jpg
Destination: /images/img.jpg
I would be thankful for help.
Upvotes: 0
Views: 698
Reputation: 9298
Try something like this:
Route:
routes.MapRoute("Image", "Images/{file}",
new { controller = "Images", action = "Images" }
);
Controller:
public ActionResult Images(string file)
{
path = "/Projects/test/images/" + file;
if (!System.IO.File.Exists(path))
{
return new HttpNotFoundResult();
}
return File(path, "image/jpeg");
}
Upvotes: 2