c# - WebAPI routing: Combining Attributes and HttpConfiguration settings -


i'm trying have get , post same route:

i've registered following:

  config.maphttpattributeroutes();    config.routes.maphttproute(                 name: "mygetmethod",                 routetemplate: "api/v1/users/{user}",                 defaults: new                               {                                   controller = "users",                                   action = "mygetmethod"                               },                 constraints: null,                 handler: httpclientfactory.createpipeline(                     new httpcontrollerdispatcher(config),                     routehandlerfactory.create()));    config.routes.maphttproute(                 name: "mysetmethod",                 routetemplate: "api/v1/users/{user}",                 defaults: new                               {                                   controller = "users",                                   action = "mysetmethod"                               },                 constraints: null,                 handler: httpclientfactory.createpipeline(                     new httpcontrollerdispatcher(config),                     routehandlerfactory.create())); 

my userscontroller.cs contains:

 [httppost]     public httpresponsemessage mysetmethod(string user)     {         return new httpresponsemessage(httpstatuscode.notimplemented);     }    [httpget]     public httpresponsemessage mygetmethod(string user)     {         return new httpresponsemessage(httpstatuscode.notimplemented);     } 

this doesn't work. get works fine, when use post webapi still redirects get method , error:

"message": "the requested resource not support http method 'post'."

if comment out registration of get method, post works fine.

is because i'm using combination between attributes [httppost], [httpget] on controller methods instead of marking them constraints?

how can have get , post on same route?

if use work

config.maphttpattributeroutes();  config.routes.maphttproute(       name: "defaultapi",       routetemplate: "api/{controller}/{id}",       defaults: new { id = routeparameter.optional }  ); 

Comments