WebAPI : Min/max double for RouteAttribute

*爱你&永不变心* 提交于 2019-12-12 01:37:41

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/36119037/webapi-min-max-double-for-routeattribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!