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) {
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: *
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?