在对我的 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 动词设置的:
我的 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/