Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match web api 2 route with forward slashes in request parameters?

I'm using Web API 2 attribute routing and I have a request which is not resolved properly.

[Route("~/foo/{bar?}")]
public void Get(string bar);

My request it's like: mydomain.me/foo/abc/def

I expect to receive bar as "abc/def" but the forward slash messes the route match. Replacing the forward slash with "%2F" doesn't solve the problem.

like image 613
Dan Avatar asked Nov 17 '13 18:11

Dan


1 Answers

You could use wildcard based matching like below:

[Route("~/foo/{*bar}")]
public string Get(string bar)
like image 86
Kiran Avatar answered Oct 14 '22 05:10

Kiran