API API + jQuery AJAX DELETE returning 404

My ASPAP WebAPI and MVC applications return a 404 error when I request PUT or DELETE. He used to return 405, but I decided that turning on CORS. I tried all kinds of solutions (disabling WebDAV, changing routes, asking for the request in the request), but no one seemed to work for me. I hope I just missed something very simple. Here is the corresponding simplified code from each corresponding file in my application:

jQuery AJAX request:

$.ajax({ url: "api/Signout?id=3", type: "DELETE", crossDomain: true, }); 

SignoutController (GET and POST methods work just fine from here):

 public void Delete([FromUri] int id) { //Do things } 

WebApiConfig Trails:

 config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); //For another part of the application config.Routes.MapHttpRoute( name: "SaveSignout", routeTemplate: "api/{controller}/{signout}" ); 

Web.config:

 <system.webServer> <httpProtocol> <customHeaders> <clear /> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /> <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" /> </customHeaders> </httpProtocol> <modules> <remove name="FormsAuthenticationModule" /> <remove name="WebDAVModule"/> </modules> <handlers> <remove name="WebDAV" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> </handlers> </system.webServer> 

RouteConfig.cs (seen this somewhere else in SO)

 routes.IgnoreRoute("{*x}", new { x = @".*\.asmx(/.*)?" }); 

Fiddler DELETE request (simplified referent):

 DELETE /api/Signout?id=45 HTTP/1.1 Host: localhost:51301 Connection: keep-alive Cache-Control: no-cache Authorization: Negotiate (large base64 here) Pragma: no-cache Accept: */* Origin: http://localhost:51301 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36 Referer: http://localhost:51301/Home/Controller/Id Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 

Fiddler answer:

 HTTP/1.1 404 Not Found Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/8.0 X-SourceFiles: =?UTF-8?B? (base64 of full local path to api/Signout) Persistent-Auth: true Access-Control-Allow-Origin: * Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS WWW-Authenticate: Negotiate oRswGaADCgEAoxIEEAEAAABDh+CIwTbjqQAAAAA= Date: Tue, 17 Feb 2015 18:05:18 GMT Content-Length: 4966 

These are just a lot of different β€œsolutions” that I came across, that everything apparently worked for those who participated. Where am I mistaken?

+7
c # asp.net-mvc asp.net-web-api
source share
2 answers

By default, IIS does not serve DELETE requests: the system.webServer handlers defined in Web.Config can set the method for processing requests when your Application Pool website has "managed pipeline mode" integrated (IIS7) or classic (ISAPI 32 and 64- bit aromas). In your example, only the ISAPI 64 bit is controlled. Other options are shown below.

 <system.webServer> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer> 

Link:

+7
source share

Richaux is correct, IIS does not execute DELETE, PUT, and other default requests. However, the Web.config part in this answer shows how this was done in the MVC4 template. When you create the MVC5 Web API project from the MVC5 template, you will see the corresponding part that registers the handler for all verbs:

 <system.webServer> <handlers> <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> </system.webServer> 
+3
source share

All Articles