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

蓝咒 提交于 2019-12-22 03:52:14

问题


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.


回答1:


You could use wildcard based matching like below:

[Route("~/foo/{*bar}")]
public string Get(string bar)


来源:https://stackoverflow.com/questions/20034227/how-to-match-web-api-2-route-with-forward-slashes-in-request-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!