WEBAPI and Attribute Routing (prior to ASP.NET 4.5)

I am using WEBAPI v1 and I had to create few more routes in my API  for user controller (on top the default 4 CRUD)

after added one more method (that gets 1 parameters) and put attribute route for it [POST(“api/Users/WhoAmI”)] I saw that when trying to POST to “..API/Users” I get exception “Multiple actions were found that match the request”

 

My problem was that since I didn’t set static route to the original method (Postuser), than the default WEBAPI method to match an action (System.Web.Http.Controllers.ApiControllerActionSelector –> SelectAction) is called and it iterating on all methods on the controller class finding several methods with one parameter and throws the exception

 

My solution was to set the STATIC route on the original method [POST(“api/Users”)] and this fixed the problem

WEBAPI and Attribute Routing (prior to ASP.NET 4.5) WEBAPI and Attribute Routing (prior to ASP.NET 4.5) Reviewed by Ran Davidovitz on 3:15 PM Rating: 5

No comments:

Powered by Blogger.