views:

558

answers:

2

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.

+8  A: 

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

Garry Shutler
+1 Just what i was looking for, thanks!
used2could
+1  A: 

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

http://msdn.microsoft.com/en-us/library/cc668201.aspx

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

Eilon