File path as MVC route argument

Part of my application maps resources stored in a number of locations onto web URLs like this:


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.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

A route like


will get the path as a single string. The * designates it as a wildcard mapping and it will consume the whole URL after "Files/".

Method 2

For more information on ASP.NET’s Routing feature, please see MSDN:

And for the “catch-all” parameters you want to use, see the section under “Handling a Variable Number of Segments”.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x