I have a ASP.NET Web API 2 controller in a custom Area. (I also have some API controllers in the default route)
I have registered the route:
// Web API routes
config.MapHttpAttributeRoutes();
// NEW ROUTE FOR AREAS
config.Routes.MapHttpRoute(
name: "API Area MyArea",
routeTemplate: "api/MyArea/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
My controller and method:
[RoutePrefix("myarea/api/accountapi")]
public class AccountAPIController : ApiController
{
...
[System.Web.Http.HttpGet]
[AcceptVerbs("GET")]
[AllowAnonymous]
[Route("emailexists")]
public async Task<IHttpActionResult> EmailExsists([FromUri]string email)
{
var user = await UserManager.FindByEmailAsync(email).ConfigureAwait(false);
return Ok(user != null);
}
...
}
But I can't get this to work, no matter what I try I get: https://localhost:44300/api/accountapi/[email protected]
{"message":"The requested resource does not support http method 'GET'."}
In fact, I can't get it to return an expected 404. For example, this: https://localhost:44300/api/accountapi/jibberish
Also returns a 405.
My API controllers in the default route works as expected, i.e. returning a 404 when it should.
Any ideas ?
type: "POST". - Emre Bolat