I think the others were very close. Try the following:
[RoutePrefix("api")] // or maybe "api/", can't recall OTTOMH... public class MyController : ApiController { [Route("MyController")] [HttpPost] public HttpResponseMessage Post([FromBody]string value)
and then request /api/MyController
If this does not work, use RouteDebugger to analyze your routes and why it rejects the match. Change your question with what you see in RouteDebugger so that I can track what doesn't match.
In addition, you may need to call MapHttpAttributeRoutes in your Register function, but not sure about it.
Edit
Now, when I look at him again, I think I see more problems with him.
First, start with the template:
Here is what you have (from your question):
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}", defaults: new { id = System.Web.Http.RouteParameter.Optional });
The odd part here is that your template does not have a {id} segment, but is defined as optional. It looks like it is missing from the template and the route should be changed to:
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional });
Note that you also removed the default action - I'm not sure that MVC automatically uses the method search convention method named Post , but I suppose it does.
The second problem is that your method signature (again from your question):
public HttpResponseMessage Post([FromBody]string value)
It defines a Post that takes a parameter named value , while your route defines a parameter called id . Therefore, there is another mismatch. You can rename a variable or decorate (see below). In addition, {id} optionally marked, but I believe (and I donβt remember OTTOMH exactly) you need to specify a default value for those cases when {id} not provided, and therefore are combined together:
public HttpResponseMessage Post([FromBody(Name="id")]string value = null)
This should fix it, although there may be more problems ... but let's start with them.