.NET Web API 2 和 IIS PUT/DELETE 不工作

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

在对我的 Web API 2 Controller 发出 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) 

我的 Controller 看起来像:

    [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 有 * 用于动词:

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

我错过了什么?

最佳答案

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

关于.NET Web API 2 和 IIS PUT/DELETE 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20083125/

相关文章:

c# - 如何在 .net 2.0 中使用 HTTP POST 使用 RESTFul web 服务

c# - 异步函数 - 使用主线程拥有的对象进行回调

c# - API 随机调用失败 - 请求被中止 : Could not create SSL/TLS secure channel

c# - Azure Web 应用程序中的 "Could not create SSL/TLS secure channel"

asp.net-mvc - 如何更改 IIS Express 8.0 安装目录,使其不使用 "My Documents"?

azure - 在没有互联网连接的情况下针对 azure AD 验证 webapi

c# - 如何使用 C#2010 将图表图像复制到剪贴板?

c# - Angular 2 Http 删除 header 以便与 Web API REST 一起使用

javascript - AJAX 不会从 Web api C# 返回值

.net - 如何动态刷新 .NET 数据绑定(bind)转发器控件