You are very close. It should be
"Image/{*file}"
That way file
will contain everyting in the URL following Image/
.
سؤال
How can I add a route that would catch all URLs pointing to a controller so that all arguments after the controller name gets transformed into a single argument string?
I need this sort of mapping:
URL /Image/foo.png -> Controller: Image, Action: Index, argument "foo.png"
URL /Image/A/foo.png -> Controller: Image, Action: Index, argument "/A/foo.png"
URL /Image/A/B/foo.png -> Controller: Image, Action: Index, argument "/A/B/bar.png"
This is my action inside ImageController
public ImageResult Index(string file)
{
// foo bar
}
This is what I tried
routes.MapRoute(null, "Image/{file*}", new { controller = "Image", action = "Index" });
URL /Image/baz.png
works, file is "baz.png". URL /Image/A/foo.png
does not work, my action is not hit.
المحلول
You are very close. It should be
"Image/{*file}"
That way file
will contain everyting in the URL following Image/
.