c# - Web API 2 default routing scheme -
this question pops in mind.
in startup.cs
have:
httpconfiguration config = new httpconfiguration(); config.maphttpattributeroutes(); app.usewebapi(config);
when have method one:
[routeprefix("api/order")] public class ordercontroller : apicontroller { // don't use attribute here public ihttpactionresult helloworld() { ... return ok(); } }
- is possible access
helloworld()
? - should
get
orpost
or whatever action sent?
you can access httpworld()
using if rename method as: gethelloworld()
. same post renaming posthelloworld()
.
but prefer using [httpget]
, [httppost]
, ... attributes, if action methods has "get" or "post" characters in name, avoid possible errors.
updated
after making tests, realised comments not possible call helloworld not correct. indeed possible call helloworld() method if make post call http://<yourprojecturl>/order
.
so, default method post and, haven't configured route action method (take in account routeprefix prefix, needs route attribute considered), controller name without "controller" (ordercontroller -> order).
Comments
Post a Comment