Reputation: 4863
I have an API in my code with a route prefix but when I try to hit it, I get a 404. This is my code:
namespace MyProject.Authentication.Controllers
{
[RoutePrefix("api/user")]
public class MyUserController : ApiController
{
private readonly IMyDomainService _myDomainService;
public MyUserController()
{
_myDomainService = new MyDomainService();
}
[HttpGet]
[HttpRoute("get/test")]
public HttpResponseMessage Test()
{
return Request.CreateResponse(HttpStatusCode.OK, "test success");
}
}
}
when I try to hit mysite.com/api/user/get/test I get a 404.
I checked AttributeRoutingHttpConfig.cs and this is what looks like, same as I have in other projects where the APIs work fine:
public static class AttributeRoutingHttpConfig
{
public static void RegisterRoutes(HttpRouteCollection routes)
{
// See http://github.com/mccalltd/AttributeRouting/wiki for more options.
// To debug routes locally using the built in ASP.NET development server, go to /routes.axd
routes.MapHttpAttributeRoutes();
}
public static void Start()
{
RegisterRoutes(GlobalConfiguration.Configuration.Routes);
}
}
edit: this is in ASP.NET 4.5
Upvotes: 0
Views: 1884
Reputation: 784
Are you sure it should not be using the RouteAttribute
to decorate the action rather than HttpRouteAttribute
, you've not created that by using the intellisense to create a class with the name HttpRouteAttribute
accidentally have you?
Upvotes: 3