3

I have the following method:

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

It works fine when I call...

GET /v1/api/request/GetEditorialRequestsByCoordinates/48/2 

But I want to pass double value like this:

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

I got an error (404 not found). Seems, it can't find appropriate method by route. I have tried to set route by way:

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

...but it does not work either.

How can I fix it?

1 Answer 1

10

Simply adding a / to the end of the URL corrected it for me. Looks like the routing engine is viewing it as a 2.777 file extension, rather than an input parameter.

Additionally, it looks like you can register a custom route that automatically adds a trailing slash to the end of the URL when using the built-in helpers to generate the link.

he easiest solution is to just add the following line to your RouteCollection. Not sure how you would do it with the attribute, but in your RouteConfig, you just add this:

routes.AppendTrailingSlash = true; 

For more details check here.

last of all max and min function works for integer

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

I think it does not work for double.

Sign up to request clarification or add additional context in comments.

1 Comment

Half of problem is solved, but does not work with range limitation. I have created one more question: stackoverflow.com/questions/36119037/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.