Return an error when invalid parameters are specified in ASP Web API

前端 未结 3 1222
长情又很酷
长情又很酷 2021-01-26 15:03

I\'m creating an API using C# and ASP.NET Web API and I want it to return an error when a parameter is used that isn\'t recognised.

For example:

/api/Eve         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-26 16:01

    I think you should be override methods
    Example:

    [Route("/app/Events/{startTime})"]
    public ApiResponse Get(string startTime)
    {
    }
    


    [Route("/app/Events/{startTime}/{someRandomeInvalid}")]
    public ApiResponse Get(string startTime, string someRandomeInvalid)
    {
    }
    


    Don't set explicit parameters name. You should be manage/check by order of parameter

提交回复
热议问题