c# - Ho to access the Action from WebApiController with many actions and same parameters -


I do not see the problem, I have an appicentron with many actions, when I request someone I have the following exception, thanks in advance.

// angular script

  var app = angular Module ('app'); Returns {addUserToRole: Function (data) {Return $ http ({method: 'POST', url: defaultUrl + '/' app.fasiner ('user repository', function ($ http) {var defaultUrl = 'api / UsersApi' + 'AddUserToRole', data: {RoleId: data.RoleId, UserId: data.User.UserId}})}}}}); // API Controller Public Class UserApcCentron: API Controller {UserRegotory Erepe; Rolleropository rrp; [Authorize] [http post] Public HTTPPPS Pensions Message AddUserToRole (Int32 RoleId, Int32 UserId) {try} URL = New user repository (); URep.AddUserToRole (UserId, RoleId); } Grip (Exceptional Exceptions) {New HTTPPasspation Expression (HTTTPTAS code.NotFrog); } Return the new HTTPPRESS Pacemase (HTTP.txtcode.ok); } {} " ", Default: new {id = route Parmeter.Optional}); Config.routes.MapHttpRoute (name: "DefaultApi2", MargTemplate: "API / {controller} / {action}"); }}  

After the request I have the result:

This XML file does not contain any style information associated with it. The document tree is shown below. The requested resource does not support the HTTP method 'GET'

If I change HttpPost to HttpGet, then the following error appears

This XML file contains any style information associated with it The document is shown below the tree. No HTTP resource found, no action was found on the controller 'UsersApi' matching the request that matches the request 'URI' / API / UserAp / AdUserTorol ''.

Within your service in your addUserToRole function, set the data with the set parameters Instead of :

  parameter: {RoleId: data.RoleId, UserId: data.User.UserId}  

In addition, your web API Check the route configs to ensure that you are requesting multiple requests for an administrator using the same HTTP method, do so that you include the action names within the root config . New {ID = RootPamator. Optional}:

  config.routes.MapHttpRoute (name: "DefaultApi", route content: "API / {controller} / {action} / {ID}", default: );  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -