【问题标题】:.NET Web API 2 and IIS PUT/DELETE not working.NET Web API 2 和 IIS PUT/DELETE 不起作用
【发布时间】:2013-12-03 16:32:25
【问题描述】:

在向我的 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 动词:

我的 web.config 有 * 表示动词:

<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>

我错过了什么?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-12-06
      • 2012-06-10
      • 2015-04-19
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      相关资源
      最近更新 更多