Below is the WebAPI.
[RoutePrefix("api/customer")]
public class CustomerController : ApiController
{
[Route("{id:int:min(1)}/")]
public HttpResponseMessage Get(int id)
{
}
}
If I pass any value less than 1 (e.g. 0 or -1). It returns the response body as null withHttpStatusCode = 200
Expected answer: HttpStatus Code = 404.
However, if I change my route as shown below.
[RoutePrefix("api/customer")]
public class CustomerController : ApiController
{
[Route("detail/{id:int:min(1)}/")]
public HttpResponseMessage Get(int id)
{
}
}
Now, if I pass a value less than 1, I get the expected response, i.e. 404.
http://localhost:8080/api/customer/detail/-1 returns - 404.(Desired response).
http://localhost:8080/api/customer/-1 returns - Null.(Not correct).
What causes this and how can I fix it?
Any help / suggestion was greatly appreciated.
source
share