在对我的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有* 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>
我错过了什么?
答案 0 :(得分:5)
路由模板中不存在id
参数。将控制器级路由更改为[Route("api/apps/{id?}")]
或者从查询字符串...