c# - Why is my route-enabled HttpGet method viewed as not supporting GET? -
i have pair of , post web api methods work fine. have pair seem set exact same way, , yet method refuses accept calls. attempts end msg, "the requested resource not support http method 'get'."
yet (again) method set , decorated same working one.
here working 1 (both unlabeled "get" (first method) , labeled "post" entered when called):
[routeprefix("api/pricecompliance")] public class pricecompliancecontroller : apicontroller { [route("{unit}/{begindate}")] public httpresponsemessage get(string unit, string begindate) { . . . [route("{unit}/{begindate}")] [httppost] public void post(string unit, string begindate) { . . . ...and here pair seem identical (different name, of course, , 1 more parameter):
[routeprefix("api/produceusage")] public class produceusagecontroller : apicontroller { [route("{unit}/{begindate}/{enddate}")] public httpresponsemessage get(string unit, string beginrange, string endrange) { . . . [route("{unit}/{begindate}/{enddate}")] [httppost] public void post(string unit, string begindate, string enddate) { . . . as mentioned, non-working second block code, when try call "get", get:
the requested resource not support http method 'get'.
i have attribute routing set so:
public static class webapiconfig { public static void register(httpconfiguration config) { // web api configuration , services // configure web api use bearer token authentication. config.suppressdefaulthostauthentication(); config.filters.add(new hostauthenticationfilter(oauthdefaults.authenticationtype)); // web api routes config.maphttpattributeroutes(); why might not supported in latter case?
both when try call clicking link url , when try call postman "http://localhost:52194/api/produceusage/gramps/201312/201412", same "get not supported" jazz.
it turned out had change this:
public httpresponsemessage get(string unit, string beginrange, string endrange) ...to this:
public httpresponsemessage get(string unit, string begindate, string enddate) ...so parameter names matched in route:
[route("{unit}/{begindate}/{enddate}")] why matters don't know, does.
Comments
Post a Comment