Attribute route constraint that includes forward slash

Topics: ASP.NET Web API
Oct 21, 2013 at 2:36 PM
We use RavenDB on the back-end and all our DB ids are strings with forward slashes
e.g. users/123

Similarly our API routes are like /api/users/123/foo

So I need to map my controller's userId parameter to "users/123"

I tried adding a regex constraint for users/\d+ but it didn't work. As I understand it, it didn't work because Web API will split the URL before applying the constraints.

What customization steps do I have to make to for this to work?

Thanks
Nov 26, 2013 at 2:44 PM
Anyone care to give some pointers on what needs to be replaced to make this happen?
Coordinator
Nov 26, 2013 at 8:35 PM
How about /api/{userGroup}/{userId} and then handle the concatenation in code?

Daniel Roth
Nov 26, 2013 at 11:04 PM
That could become very cumbersome over several controllers with several actions...

Sent from my iPad

Nov 26, 2013 at 11:35 PM
You can use a wildcard constraint:
    [Route("api/users/{*id}")]
Nov 27, 2013 at 8:56 AM
Mike that would only work if the id is always trailing

Isn't there a way to replace the rule matching to controllers/actions?