405 method not allowed Web API

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

    I tried many thing to get DELETE method work (I was getting 405 method not allowed web api) , and finally I added [Route("api/scan/{id}")] to my controller and was work fine. hope this post help some one.

         // DELETE api/Scan/5
        [Route("api/scan/{id}")]
        [ResponseType(typeof(Scan))]
        public IHttpActionResult DeleteScan(int id)
        {
            Scan scan = db.Scans.Find(id);
            if (scan == null)
            {
                return NotFound();
            }
    
            db.Scans.Remove(scan);
            db.SaveChanges();
    
            return Ok(scan);
        }
    

提交回复
热议问题