的WebAPI:对于RouteAttribute最小/最大双 [英] WebAPI : Min/max double for RouteAttribute
问题描述
我有以下API方法:
[路线(GetEditorialRequestsByCoordinates / {纬度:双} / {LNG:双})]
[AutomapperExceptionApiFilterAttribute]
公众的Htt presponseMessage GetEditorialRequestsByCoordinates(双纬度,双LNG)
{}
它工作正常,像要求:
GET /v1/api/request/GetEditorialRequestsByCoordinates/48.999/2.777/
不过,我想为纬度和经度加限制(最小值和最大值)。
请按照这篇文章:<一href=\"http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2\" rel=\"nofollow\">http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
最大匹配具有最大值的整数。 {X:最大(10)}
分匹配以最小的整数。 {X:分钟(10)}
块引用>尝试创建这样的路线:
<$p$p><$c$c>[Route(\"GetEditorialRequestsByCoordinates/{lat:double:min(-90):max(90)}/{lng:double:min(-180):max(180)}\")]
和我得到的404错误。为什么呢?
解决方案你给的资料告诉函数适用于整数
最大:匹配具有最大值整数的{X:最大(10)}
我觉得它并不适用于双工作。
你可以看到这链接来创建自己的IHttpRouteConstraint。
I have the following API method:
[Route("GetEditorialRequestsByCoordinates/{lat:double}/{lng:double}")] [AutomapperExceptionApiFilterAttribute] public HttpResponseMessage GetEditorialRequestsByCoordinates(double lat, double lng) { }
it works fine for request like:
GET /v1/api/request/GetEditorialRequestsByCoordinates/48.999/2.777/
But I want to add limit (minimum and maximum) for lat and lng.
Follow this article: 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)}
Try to create such route:
[Route("GetEditorialRequestsByCoordinates/{lat:double:min(-90):max(90)}/{lng:double:min(-180):max(180)}")]
and I get 404 error. Why?
解决方案The documentation you give tells that functions works for integer
max: Matches an integer with a maximum value. {x:max(10)}
I think it does not work for double.
you can see this link to create your own IHttpRouteConstraint.
这篇关于的WebAPI:对于RouteAttribute最小/最大双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!