WebAPI:Min/max RouteAttribute 加倍

WebAPI : Min/max double for RouteAttribute

我有以下API方法:

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

}

它适用于像这样的请求:

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

但我想为纬度和经度添加限制(最小值和最大值)。

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

max Matches an integer with a maximum value. {x:max(10)}

min Matches an integer with a minimum value. {x:min(10)}

尝试创建这样的路线:

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

我收到 404 错误。为什么?

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

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

我认为它不适用于 double。

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