asp.net - WebApi route not working -


here route:

config.routes.maphttproute(    name: "createuser",    routetemplate: "api/user/createuser",    defaults: new { controller = "user", action = "createuser" } ); 

here endpoint:

[httppost] public async task<user> createuser([frombody] user user) {     db.directusers.add(user);     await db.savechangesasync();     return user; } 

i sending post data:

{     "userid" : 1     "name" : "nick"     "twitterhandel" : "x" } 

to : http://localhost:56792/api/user/createuser

but im getting 404

ideally, not need add routes each action method. 1 route configuration enough normal api.

if need advanced routing, can @ web api 2's attribute routing.

public static void register(httpconfiguration config) {     config.maphttpattributeroutes();      // alone enough.     config.routes.maphttproute(         name: "defaultapi",         routetemplate: "api/{controller}/{id}",         defaults: new {id = routeparameter.optional});      ... } 

beside, should not access via http://.../api/user/createuser. defeats purpose of using web api in action methods mapped http verbs.

so need httpost url creating new user.

http://localhost:56792/api/user/


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -