Web API: Same Method with different HTTP Verbs

后端 未结 4 631
鱼传尺愫
鱼传尺愫 2021-01-06 12:48

In a WEB API controller, can we have the same method name with different HTTP Verbs?

  [HttpGet]
        public string Test()
        {
            return \"         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 13:35

    Add seperate route on your conflicting methods. Such as [Route("GetByType")] above of one and [Route("GetById")] on another.

    OR, for ASP.NET Core, on startup file for swagger add the below configuration:

     services.AddSwaggerGen(options =>
                {
                    options.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
    }
    

提交回复
热议问题