working in asp.net 4.6 here.
i have controller:
public class computercontroller : apicontroller { ... [httpget] [route("api/computer/ping")] public ihttpactionresult ping(int id) { return ok("hello"); } ... }
going this answer (look @ mstdev's answer), have in webapiconfig.cs
:
// can use [route]? config.maphttpattributeroutes(); // handle defaults. config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } );
the route doesn't work.
no http resource found matches request uri 'http://localhost:29365/api/computer/ping'.
this seems such simple problem, yet remain stumped. help?
your route missing {id} parameter. ex.
[route("api/category/{categoryid}")] public ienumerable<order> getcategoryid(int categoryid) { ... }
your controller should this:
public class computercontroller : apicontroller { ... [httpget] [route("api/computer/ping/{id}")] public ihttpactionresult ping(int id) { return ok("hello"); } ... }
Comments
Post a Comment