WEB API2 / HTTP DELETE is not triggering - 405 error
<p>Hi i am trying to delete the record (HttpDelete).the method in the controller is not triggering and getting 405 Method Not Allowed error.</p>

<p>jquery below</p>

<pre><code> function deleteContract(contractId) {
            var contract = new Object();
            contract.ContractID = "ContractId";
            $.ajax({
                async: true,
                type: 'DELETE',
                data: contract,
                dataType: "json",
                url: 'http://localhost:4233/api/Contract/DeleteContractById/' + contractId,
            }).done(function (data, textStatus, xhr) {
               alert("deleted successfully")
            }).error(function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText || textStatus);
            })
        }
</code></pre>

<p>controller below</p>

<pre><code> // DELETE: api/Contract/5
    [ResponseType(typeof(Contract))]
    [AllowAnonymous]
    [HttpDelete]
    [ActionName("DeleteContractById")]
    //[Route("api/Contract/{id}")]
    [AcceptVerbs("DELETE")]
    public HttpResponseMessage DeleteContract(Guid id)
    {
        Contract contract = db.Contract.Find(id);
        if (contract == null)
        {
            return Request.CreateResponse(HttpStatusCode.NotFound);
        }

        db.Strata.Remove(contract);
        db.SaveChanges();
        return Request.CreateResponse(HttpStatusCode.OK, contract);
    }
</code></pre>

<p>webapiconfig below</p>

<pre><code>public static void Register(HttpConfiguration config)
    {
                config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

                config.MapHttpAttributeRoutes();

           config.Routes.MapHttpRoute(
           name: "ControllerAndAction",
           routeTemplate: "api/{controller}/{action}/{id}",
           defaults: new { action = "GET", id = RouteParameter.Optional }
       );

    }
</code></pre>

<p>web config below</p>

<pre><code> &lt;system.webServer&gt;
    &lt;validation validateIntegratedModeConfiguration="false"/&gt;
    &lt;modules runAllManagedModulesForAllRequests="true"&gt;
      &lt;remove name="WebDAVModule"/&gt;
    &lt;/modules&gt;

  &lt;handlers&gt;
    &lt;remove name="WebDAV" /&gt;
      &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt;
      &lt;remove name="OPTIONSVerbHandler" /&gt;
      &lt;remove name="TRACEVerbHandler" /&gt;
      &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt;
    &lt;/handlers&gt;
   &lt;httpProtocol&gt;
  &lt;customHeaders&gt;
    &lt;add name="Access-Control-Allow-Origin" value="*" /&gt;
    &lt;add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" /&gt;
  &lt;/customHeaders&gt;
&lt;/httpProtocol&gt;
    &lt;/system.webServer&gt;
</code></pre>

<p>when i make the call using fiddler its working fine. let me know if i have missed out any settings in the code.</p>

<p>Thanks
Dev</p>