c# - Web API 2 routing - Route attribute -
question regarding defining custom routes route
attribute.
i know in webapiconfig
class define default route,
configuration.routes.maphttproute("api default", "api/{controller}/{id}", new { id = routeparameter.optional });
what cannot working when want pass parameter. know can (code below defined underneath default route listed above):
//configuration.routes.maphttproute( // name: "getbrandimagepaths", // routetemplate: "api/{controller}/{id}/{type}");
but i'd rather, instead of defining these routes in webapiconfig
file, use custom routing. however, if not have commented out code above in file, 404. there leading me believe custom route
not being looked at.
public class helperapicontroller : apicontroller { [httpget] [route("api/helperapi/{id}/{type}")] public string getbrandimages(int id, string type) { ..... } }
how can have can use routes defined in webapiconfig
file, , defining custom routes inside individual api controllers.
note project mvc project (not webapi). there i'm missing, doing incorrectly etc? know there's numerous posts out there defining how pass multiple params, think question little more specific on why 1 works , not other.
you need call config.maphttpattributeroutes()
.
this parse controller
classes , derive routes attributes.
i not mix standard routing.
Comments
Post a Comment