3

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?

1
  • 1
    Change route to: [Route("Values/{id}")]. Commented Jan 20, 2017 at 18:01

1 Answer 1

5

Update your route to

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.