TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
L A
NA
170
171.2k
WebAPI - [DELETE] 405 Method Not Allowed
Aug 22 2017 1:39 PM
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.
public
HttpResponseMessage Delete (
int
empId)
{
try
{
using
(WebApiTrialEntities entity =
new
WebApiTrialEntities())
{
var isAvailable = entity.Employees.FirstOrDefault(e => e.ID == empId);
if
(isAvailable !=
null
)
{
entity.Employees.Remove(isAvailable);
entity.SaveChangesAsync();
return
Request.CreateResponse(HttpStatusCode.Gone,
"EmpId "
+ empId +
" is Deleted"
);
}
else
{
return
Request.CreateErrorResponse(HttpStatusCode.NotFound,
"EmpId "
+ empId +
" is NotFound"
);
}
}
}
catch
(Exception ex)
{
return
Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
Using Fiddler - we see Header value as '
405 Method Not Allowed' wi
th message as
"The requested resource does not support http method 'DELETE'
.
Please help me out & suggest me to correct my mistakes.
Thanks in advance.
Reply
Answers (
7
)
How to make a wcf service public hosted on local iis.
Hosting ASP.NET Web API REST Service On Http server