Getting 404 error calling a HttpDelete method in WebAPI?

I was playing with KnockoutJS and MVC version 4 today, and wanted to call a Web API Delete method to clear out my data on the server.

Although my Get requests to the API controller were working fine and returning JSON data, every time I tried to make an AJAX call with a HttpDelete verb, I got a 404 error.

I even loaded Fiddler and tried posting a DELETE directly to the API, but continued to get a 404 error plus a lot of HTML from IIS about the resource not being found.

After a lot of searching, I found this StackOverflow article which explained the same problem and had two solutions. While both work, the correct approach is to add the following lines to the system.webServer section of web.config:

  <remove name="UrlRoutingModule-4.0" />
  <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  <!– any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. –>
</modules>