简体   繁体   中英

Error occurs while calling HttpPut and HttpDelete in C# WebAPI

I have a WebAPI 2 controller. Very easy, very simple:

public class ValuesController : ApiController
{
    // GET api/values
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/values/5
    public string Get(int id)
    {
        return "value";
    }

    // POST api/values
    public void Post([FromBody]string value)
    {
    }

    // PUT api/values/5
    public void Put(int id, string value)
    {
    }

    // DELETE api/values/5
    public void Delete(int id)
    {
    }
}

Get and Post methods work well. But Delete and Put do not work. And this error occurs:

HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

*All methods work well in IIS Express. But not in IIS Local Any idea why is that happening? Thanks in advance

From where you are sending request to this methods? From AJAX request? GET (with id) PUT and DELETE have same route URL. You have to specify the verb if you are calling via AJAX. Otherwise application gets confused between GET, PUT and DELETE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM