2
Answers

WebAPI - [DELETE] 405 Method Not Allowed

Learn Avid

Learn Avid

7y
1.1k
1
Hello all,
 
Firstly, the topic is related to WebAPI but i didn`t see any category with WebAPI. So posted under Web services.
I`m working on a WebAPI application (ASP.NET MVC, Entity Framework) & trying to DELETE an entry from Database. Below is the code related to DELETE verb.
  1. public HttpResponseMessage Delete (int empId)  
  2. {  
  3.     try  
  4.     {  
  5.         using (WebApiTrialEntities entity = new WebApiTrialEntities())  
  6.         {  
  7.             var isAvailable = entity.Employees.FirstOrDefault(e => e.ID == empId);  
  8.             if (isAvailable !=null)  
  9.             {  
  10.                 entity.Employees.Remove(isAvailable);  
  11.                 entity.SaveChangesAsync();  
  12.                 return Request.CreateResponse(HttpStatusCode.Gone, "EmpId " + empId + " is Deleted");  
  13.             }  
  14.             else  
  15.             {  
  16.                 return Request.CreateErrorResponse(HttpStatusCode.NotFound, "EmpId " + empId + " is NotFound");  
  17.             }  
  18.         }  
  19.     }  
  20.     catch (Exception ex)  
  21.     {  
  22.         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);  
  23.     }  

Using Fiddler - we see Header value as '405 Method Not Allowed' with message as "The requested resource does not support http method 'DELETE'.
 
Please help me out & suggest me to correct my mistakes.
 
Thanks in advance.
Answers (2)
0
Learn Avid

Learn Avid

NA 101 4.8k 7y
Hello Midhun T P, thanks for your reply.
I have already made these configuration settings in Web.config but it didn't work.
0
Midhun T P

Midhun T P

NA 19.7k 281.1k 7y
Hi,
 
Please check below threads -
 
https://stackoverflow.com/questions/44540539/webapi-the-requested-resource-does-not-support-http-method-delete
 
https://stackoverflow.com/questions/20445653/asp-net-web-api-http-delete-405-method-not-allowed