I had a web API project that was working fine. I merged it with an MVC project, and now only the actions with a URI parameter work. All other actions end up with a 404 Not Found where even the controller is not found.
Here's what I have in WebApiConfig (standard stuff):
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Here is the controller class:
[Authorize]
[RoutePrefix("api/WikiPlan")]
public class WikiPlanController : ApiController
Here's the action that works:
http://localhost:2000/api/WikiPlan/SearchWikiPlans/baby
[AllowAnonymous]
[HttpGet]
[Route("SearchWikiPlans/{keyword}")]
[ResponseType(typeof(List<WikiPlanSearchResultViewModel>))]
public IHttpActionResult SearchWikiPlans(string keyword)
Here's one that doesn't work (which used to work when it was in its own project):
http://localhost:2000/api/WikiPlan/TopWikiPlans
[AllowAnonymous]
[HttpGet]
[Route("TopWikiPlans")]
[ResponseType(typeof(List<TopWikiPlan>))]
public IHttpActionResult TopWikiPlans()
I don't know what is wrong. Thanks for your help!