The following route will match any folder structure below BasePath:
http://BasePath/{*SomeFolders}/
How do I create another route which will match any zip file below the same BasePath structure?
I tried this…
http://BasePath/{*SomeFolders}/{ZipFile}
… but it errors with
A path segment that contains more than one section, such as a literal section or a parameter, cannot contain a catch-all parameter.
Parameter name: routeUrl
How should I approach this?
*Update*
The original requirements are in fact flawed.
{ZipFile} will match the final section regardless of what it contains. (File or Folder)
In reality I believe the route pattern I’m looking to match should be:
http://BasePath/{*SomeFolders}/{ZipFile}.zip
Catch all anywhere in the URL – exactly what you need
I’ve written such
Routeclass that allows you to do exactly what you describe. It allows you to put catch-all segment as the first one in the route definition (or anywhere else actually). It will allow you to define your route as:The whole thing is described into great detail on my blog post where you will find the code to this
Routeclass.Additional info
Based on added info I would still rather use the first route definition that doesn’t exclude file extension out of the route segment parameter but rather add constraint for the last segment to be
So routing should still be defined as stated above in my answer, but contraint for the
ZipFileshould be defined as previously written. This would make my special route work out of the box as it is now.To also make it work for other route delimiters (like dot in your example) code should be changed considerably, but if you know routing very well how it works, you can change it to work that way.
But I’d rather suggest you keep it simple and add a constraint.