我有一个Web Api 2控制器,如下所示:
[RoutePrefix("api/Users")]
public class UsersController : ApiController
{
[HttpPut]
[Route("permission/user")]
public IHttpActionResult UpdateUserPermission(int id, string type, string name)
{
}
[HttpPut]
[Route("permission/admin")]
public IHttpActionResult UpdateAdminPermission(int id, string name, string auth)
{
}
[HttpDelete]
[Route("permission/user")]
public IHttpActionResult DeleteUserPermission(int id, string type)
{
}
[HttpDelete]
[Route("permission/admin")]
public IHttpActionResult DeleteAdminPermission(int id, string name)
{
}
}
当我调用端点PUT时:api / Users / Permission / User?id = 1& type = sometype& name = somename它按预期工作。 DELETE也一样:api / Users / Permission / User?id = 1& type = sometype
另一方面,如果我调用端点PUT:api / Users / Permission / Admin?id = 1& name = somename& auth = someauth或DELETE:api / Users / Permission / Admin?id = 1& name = somename适用于IIS Express,但IIS返回404。
我的路线配置如下:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
我查看了IIS配置,并指定要处理的动词设置为所有动词。
为什么会发生这种情况的任何想法?
提前致谢