Part of my application maps resources stored in a number of locations onto web URLs like this:
http://servername/files/path/to/my/resource/
The resources location is modelled after file paths and as a result there can be an unlimited level of nesting. Is it possible to construct an MVC route that matches this so that I get the path in its entirety passed into my controller? Either as a single string or possibly as an params style array of strings.
I guess this requires a match on the files keyword, followed by some sort of wildcard. Though I have no idea if MVC supports this.
The MVC framework leverages routing to direct a request to a controller. The Global. asax file is that part of your application, where you will define the route for your application.
Every MVC application must configure (register) at least one route configured by the MVC framework by default. You can register a route in RouteConfig class, which is in RouteConfig. cs under App_Start folder.
RedirectToRouteResult is an ActionResult that returns a Found (302), Moved Permanently (301), Temporary Redirect (307), or Permanent Redirect (308) response with a Location header. Targets a registered route. It should be used when we want to redirect to a route.
A route like
"Files/{*path}"
will get the path as a single string. The *
designates it as a wildcard mapping and it will consume the whole URL after "Files/"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With