[Vuejs]-Http 405 MethodNotAllowed on ASP.NET Core endpoint

0👍

You should change

axios.delete("http://localhost:32961/api/request/delete"+id)

to

axios.delete("http://localhost:32961/api/request/delete/"+id)

And do this in the C# API code:

[Route("delete/{id}")]
[HttpDelete]
public IActionResult Delete(int id)
{    
    _db_Context.Requests
               .FirstOrDefault(a => a.RequestId == request.RequestId);

    _db_Context.Requests.Remove(request);
    _db_Context.SaveChanges();

    return Ok(request);
}

Or if you call Delete API with query string of id you should set FromUri in api.

See this link

0👍

Abbas Aryanpour is right in pointing out the missing / in your code. But I think the error message should be 404, not 405.

I think this should be related to your asp.net core back-end code not setting cross-domain, or you have set cross-domain, but did not notice the execution order of middleware, so it may cause cross-domain not to take effect.

Official doc:

1.Troubleshoot connection errors

2. Cross-origin resource sharing

Leave a comment