please help. I had to change routing for Web API to be able to use methods in URL:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// for MVC controllers
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Editions", action = "Index", id = UrlParameter.Optional }
);
// for Web API
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
I have a controller
public class PositionsController : ApiController
{
[HttpGet]
public JToken Approved()
{
// some code here
}
}
Everything works fine for methods with parameters, but I cannot call parameterless method like http://localhost/API/Positions/Approved
. Instead of calling Approved
method I got 404 not found error. What I did wrong?
Funny part: Calling URL http://localhost/API/Positions/Approved/whatever
works. It seems like ID is not so optional as I thought.
Thanks for any help!