参考
.NET WebApi Delete方法访问提示:“HTTP 错误 405.0 - Method Not Allowed”
WebAPI Delete方法报错405 Method Not Allowed
<system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"> <remove name="WebDAVModule" /> </modules> <handlers> <remove name="WebDAV" /> </handlers> </system.webServer>
$.ajax({ **url: "/api/SomeController/" + id,** type: "DELETE", dataType: "json", success: function(data, statusText) { alert(data); }, error: function(request, textStatus, error) { alert(error); debugger; } }); //Do not use something like this: data: {id:id}
<system.webServer> <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> <modules> <remove name="WebDAVModule" /> </modules> </system.webServer>
//We had to add custom headers to our web.config as our request had multiple headers that confused the API response. <httpProtocol> <customHeaders> <remove name="Access-Control-Allow-Methods" /> <remove name="Access-Control-Allow-Origin" /> <remove name="Access-Control-Allow-Headers" /> </customHeaders> </httpProtocol>