当IIS Express上正常工作时,IIS返回404第二个HttpPut和HttpDelete操作

时间:2016-07-14 16:32:18

标签: asp.net iis asp.net-web-api2 iis-express

我有一个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配置,并指定要处理的动词设置为所有动词。

为什么会发生这种情况的任何想法?

提前致谢

0 个答案:

没有答案