Reputation: 495
Using ASP.NET (4.6.1) Web Api on my local IIS 7.5 I'm trying to call a delete method:
[HttpDelete]
[Route("Values/")]
public IHttpActionResult DeleteValue(int id)
{
return Ok();
}
Following DELETE request works perfectly fine:
https://localhost/api/Values?id=22
But, I would like to call DELETE request like this:
https://localhost/api/Values/22
This gives me: 404.0 — Not Found
My api route config is defined like:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
My web.config looks like:
<system.webServer>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<modules>
<remove name="WebDAVModule" />
</modules>
Do I missed something?
Upvotes: 3
Views: 3522
Reputation: 3867
Update your route to
[Route("Values/{id}")]
So that it can map the request correctly to your method.
Upvotes: 5