405 method not allowed Web API

前端 未结 21 1580
栀梦
栀梦 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:37

    My problem turned out to be Attribute Routing in WebAPI. I created a custom route, and it treated it like a GET instead of WebAPI discovering it was a POST

        [Route("")]
        [HttpPost] //I added this attribute explicitly, and it worked
        public void Post(ProductModel data)
        {
            ...
        }
    

    I knew it had to be something silly (that consumes your entire day)

提交回复
热议问题