本文介绍了如何在请求参数中将Web API 2路由与正斜杠匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Web API 2属性路由,并且有一个请求无法正确解决.
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);我的请求就像: mydomain.me/foo/abc/def
我希望将bar接收为"abc/def",但正斜杠会弄乱路线匹配. 用%2F"替换正斜杠不能解决问题.
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.
推荐答案您可以使用基于通配符的匹配,如下所示:
You could use wildcard based matching like below:
[Route("~/foo/{*bar}")] public string Get(string bar)更多推荐
如何在请求参数中将Web API 2路由与正斜杠匹配?
发布评论