Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File path as MVC route argument

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.

like image 925
Jack Ryan Avatar asked Nov 27 '08 10:11

Jack Ryan


People also ask

Which file is used to define route MVC?

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.

Where is route config file in MVC?

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.

What is redirect to route in MVC?

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.


1 Answers

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/".

like image 183
Garry Shutler Avatar answered Sep 30 '22 10:09

Garry Shutler