How can I write a method that can handle both Content-Type: application/json and Content-Type: application/x-www-form-urlencoded equally well? Indeed, in the first case I need to set the [FromBody] attribute for the parameter, but in the second case ( Content-Type: application/x-www-form-urlencoded ) it will return 415 Unsupported Media Type to me if I leave [FromBody]

  • I work with "application / json" and without FromBody. Well, as an option, overloading methods! - gromanev
  • @gromanev, yes, I already understood that the question is incorrect, because my question concerns exclusively the asp.net core, everything works as it should in web api. Is it possible to learn more about method overloading? - Qutrix
  • Well, method overloading is the creation of another method that accomplishes a close target to the overloaded one, while preserving the name of the method, saving the return type, but changing the signature of the parameters - gromanev
  • @gromanev, in this case it does not fit: 1) with the addition of the attribute, the signature of the parameters will not change 2) I break the selector so (there will be two methods marked with the HttpPost attribute that will cause ambiguity when choosing a particular action) - Qutrix
  • I will reveal one secret that REST is not to follow all the rules for building a CRUD application config.Routes.MapHttpRoute (name: "DefaultApi2", routeTemplate: "api / {controller} / {action} / {id}", defaults : new {id = RouteParameter.Optional}); To help you! - gromanev

0