【问题标题】:WebAPI : Min/max double for RouteAttributeWebAPI:RouteAttribute 的最小/最大双倍
【发布时间】:2016-03-20 20:20:32
【问题描述】:

我有以下 API 方法:

[Route("GetEditorialRequestsByCoordinates/{lat:double}/{lng:double}")]
[AutomapperExceptionApiFilterAttribute]
public HttpResponseMessage GetEditorialRequestsByCoordinates(double lat, double lng)
{

}

它适用于以下请求:

GET /v1/api/request/GetEditorialRequestsByCoordinates/48.999/2.777/

但我想为 lat 和 lng 添加限制(最小值和最大值)。

关注这篇文章:http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

max 匹配具有最大值的整数。 {x:max(10)}

min 匹配具有最小值的整数。 {x:min(10)}

尝试创建这样的路由:

[Route("GetEditorialRequestsByCoordinates/{lat:double:min(-90):max(90)}/{lng:double:min(-180):max(180)}")]

我得到 404 错误。为什么?

【问题讨论】:

    标签: asp.net-web-api asp.net-web-api2 asp.net-web-api-routing


    【解决方案1】:

    您提供的文档表明函数适用于 integer

    ma​​x:匹配一个具有最大值的整数。 {x:max(10)}

    我认为它不适用于双倍。

    你可以看到这个link来创建你自己的IHttpRouteConstraint。

    【讨论】:

    • 我看到了,但理解为我们只能将 max(min) 值设置为整数值,但范围适用于任何数字类型
    • @OlegSh,你可以使用 range 和 double 吗?
    • 如果你告诉我我会为你写一个支持双倍的代码。
    猜你喜欢
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    • 2020-07-11
    • 1970-01-01
    • 2015-06-17
    相关资源
    最近更新 更多