简体   繁体   中英

ASP.NET Web API Delete returns 404

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?

Update your route to

[Route("Values/{id}")]

So that it can map the request correctly to your method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM