I have the following controller action methods in an ASP.NET Web API project:
[Route("api/v2/project/{projectId}/stuff"), HttpGet] public IHttpActionResult Get(int projectId) [Route("api/v2/project/{projectId}/stuff/{id:guid}"), HttpGet] public IHttpActionResult Get(int projectId, [FromUri] Guid id) [Route("api/v2/project/{projectId}/stuff"), HttpPost] public IHttpActionResult Post(int projectId, [Required] Stuff stuff) [Route("api/v2/project/{projectId}/stuff/{id:guid}"), HttpPut] public IHttpActionResult Put(int projectId, [FromUri] Guid blastId, Stuff stuff) [Route("api/v2/project/{projectId}/stuff/{id:guid}"), HttpDelete] public IHttpActionResult Delete(int projectId, [FromUri] Guid id)
Due to javascript error, I made a DELETE request for
api/v2/project/1234/stuff/undefined
i.e. instead of the GUID for id, I got the string "undefined" . As far as I can tell, this should not match any of my routes, but instead of 404 Not found (or even 405 Method not allowed ) I got a 200 OK response.
I set a breakpoint in each of these action methods and retried the request using Fiddler, but none of the breakpoints were deleted. I also tried installing the WebApiRouteDebugger package from nuget, but we use a custom factory controller that intercepts things through our DI container, so I could not get it to work at all. I even tried to make the following exception from one of my global filters:
throw new Exception(actionContext.ControllerContext.ControllerDescriptor.ControllerName + " " + actionContext.ActionDescriptor.ActionName);
but the DELETE request still passes up to 200 OK (no requests for valid URLs seem to do this).
How else can I fix this problem? What could be the main reason?
Tomas lycken
source share