405 method not allowed Web API

前端 未结 21 1566
栀梦
栀梦 2020-11-27 18:33

This error is very common, and I tried all of the solutions and non of them worked. I have disabled WebDAV publishing in control panel and added this to my web config file:<

21条回答
  •  [愿得一人]
    2020-11-27 18:44

    If you have a route like

    [Route("nuclearreactors/{reactorId}")]
    

    You need to use the exact same parameter name in the method e.g.

    public ReactorModel GetReactor(reactorId)
    {
     ...
    }
    

    If you do not pass the exact same parameter you may get the error "405 method not allowed" because the route will not match the request and WebApi will hit a different controller method with different allowed HTTP method.

提交回复
热议问题