如何在请求参数中将Web API 2路由与正斜杠匹配?

编程入门 行业动态 更新时间:2024-10-17 19:30:07
本文介绍了如何在请求参数中将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路由与正斜杠匹配?

本文发布于:2023-11-02 17:06:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552943.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜杠   路由   中将   参数   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!