When I run this url: /api/users/1
it does only map to the Delete action when I use the HttpDelete-Attribute. What is the reason for this behavior?
Else I get his message: The requested resource does not support HTTP method GET
[RoutePrefix("api/users")]
public class UserController : ApiController
{
private readonly IUserService _userService;
public UserController(IUserService userService)
{
_userService = userService;
}
[Route("")]
public HttpResponseMessage Get()
{
return Request.CreateResponse<IEnumerable<UserDTO>>(HttpStatusCode.OK, _userService.GetUsers());
}
[Route("{id:int}")]
[HttpDelete]
public HttpResponseMessage Delete(int id)
{
_userService.Delete(id);
return Request.CreateResponse(HttpStatusCode.OK, "User was deleted successfully");
}
}
These are my routes:
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { controller = "Home", action = "Start", id = RouteParameter.Optional }
);