No action was found on the controller that matches the request

Ok- thanks for the help peeps!

This what I did to get it working:

  1. Removed the "static" from the GetListOfStudents function.
  2. Added the route below.
config.Routes.MapHttpRoute(
  name: "ApiByAction",
  routeTemplate: "api/products/GetListOfStudents/{username}/{password}",
  defaults: new { controller = "products", action = "GetListOfStudents" }
);

Thanks everyone for your help!


Your GetListOfStudents action requires two parameters, username and password. Yet, the route definition contains neither specification in the route template where the values for those parameters should come from, nor specification for those parameter defaults in the defaults: parameter definition.

So when request comes in, routing is able to find your controller, but it is unable to find the action that it can call with the request and route context that it has because it has no information for the username and password parameters.


When registering your global api access point, you should tell the config which route to use in the following manner:

config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/{controller}/{action}
defaults: new { controller = "products", action = "GetListOfStudents" });

In this sample you explicitly tell the controller it should only go to the "products" controller, you can make it generic without specifying the control or the action, just omit the defaults, like this:

config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/{controller}/{action}

That should do the job :)