Hi i am trying to delete the record (HttpDelete).the method in the controller is not triggering and getting 405 Method Not Allowed error.
jquery below
 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);
            })
        }
controller below
 // 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);
    }
webapiconfig below
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 }
       );
    }
web config below
 <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule"/>
    </modules>
  <handlers>
    <remove name="WebDAV" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
   <httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" />
  </customHeaders>
</httpProtocol>
    </system.webServer>
when i make the call using fiddler its working fine. let me know if i have missed out any settings in the code.
Thanks Dev
 
     
     
     
    