简体   繁体   English

在Web API Rest Service中将负数作为ID传递

[英]rePass negative number as ids in web api rest service

I have created a rest API using Microsoft web api. 我已经使用Microsoft Web API创建了Rest API。 I use negative numbers to do some business logic. 我使用负数来做一些业务逻辑。

When I pass positive numbers to GET calls, the api returns proper response. 当我将正数传递给GET调用时,api返回正确的响应。 However when I pass negative number as Id, API ignores it and return all the data. 但是,当我将负数作为ID传递时,API会忽略它并返回所有数据。

How can I force to treat negative numbers as valid? 如何强制将负数视为有效?

Thanks 谢谢

using System.Net.Http;
using System.Web.Http;
[RoutePrefix("Somethings")]
public class SomethingsController : ApiController
{
    [Route("{Id:int}")]
    [HttpGet]
    public HttpResponse GetSomethings(int id)
    {
        //Do Business logic
        return response;
    }

}



http://localhost/Somethings/-1 GET will hit GetSomethings method.

I am sure this will work for negative numbers. 我确信这将对负数有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM