.NET Web API 2和IIS PUT / DELETE无法正常工作

时间:2013-11-19 22:09:20

标签: .net iis asp.net-web-api

在对我的Web API 2控制器的DELETE请求中,我得到:

Request URL:http://localhost/phoenix/api/apps/1245 
Request Method:DELETE
Status Code:404 Not Found

DELETE http://localhost/myapp/api/apps/1245 404 (Not Found) 

我的控制器看起来像:

    [EnableCors(origins: "http://localhost", headers: "*", methods: "*", SupportsCredentials = true)]
[Route("api/apps")]
public class ApplicationController : ApiController
{
    // DELETE api/apps/5
    public void Delete(string id)
    {
        //apps.Delete(id);
    }
}

我的IIS是为PUT / DELETE动词设置的:

enter image description here

我的web.config有* for 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>

我错过了什么?

1 个答案:

答案 0 :(得分:5)

路由模板中不存在id参数。将控制器级路由更改为[Route("api/apps/{id?}")]或者从查询字符串...

提供id值