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();     } } 

  1. is possible access helloworld()?
  2. should get or post 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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -