ASP.NET MVC Routing for Files with Multiple Subdirectories

I need to configure a file handler for routing with several auxiliary directories, for example, tihs;

http://localhost/images/7/99/786936215595.jpg

I tried putting this in a global.asax file;

 routes.Add(
   "ImageRoute",
   new Route("covers/{filepath}/{filename}",
   new ImageRouteHandler()));

I use the ImageHandler found in this Question , which works fine if you have one subdirectory (e.g. '/ images / 15/786936215595. Jpg'), but it fails if there are multiple directories.

I tried setting up a wildcard and it didn’t work (i.e. "new route" ("cover / {filepath) / * / {filename}" ')

This serves images from a large NAS (I think it's something like 3 million images), so its not like I can just move files.

Thank!

+5
2

google fu , .

:

 routes.Add(
     "ImageRoute",
     new Route("images/{*filepath}",
     new ImageRouteHandler()));

MapRoute . "*" , MVC , -, , RouteData. GetHttpHandler() , :

string fp = requestContext.RouteData.Values["filepath"] as string;

Woot!

+3

? :

routes.Add(
    "ImageRoute",
    "/images/{path}",
    new { controller = "Image", action = "Image" }
);

ActionResult Image(string path) { }?

0

All Articles