This is
one of common issue one may face while working with Web API, there can be
certain reasons due to which DELETE or PUT method not working with Web API.
Here I’ll try to include three possible issues and there fixes:
Possible
issues and solution:
Issue
1:
Error:
HTTP Error 405.0 - Method Not Allowed The page you are looking for cannot be
displayed because an invalid method (HTTP Verb) is being used
You are
facing this issue because your application is not able to handles all types of HTTP
requests. In order to execute HTTP requests for DELETE, PUT, etc., we need to
add the below mentioned line in web.config file under <system.webServer>
<modules runallmanagedmodulesforallrequests="true">
|
Issue 2:
Error:
Getting 404 for PUT and DELETE request: Issue may be due to because Web API provides default GET, POST, PUT and DELETE methods but IIS
restricts it. To fix the issue you need to manage the handler mappings in IIS
and then need to add PUT and DELETE on the “Verbs” tab. check this post for
solution of this issue
Issue 3:
Issue
with “content-type: text/plain” (posted string parameter value is NULL): If you are posting data with “content-type:
text/plain” to a Web API method that takes a string, you notice that the value
in the string is null, this is because of your application not having support
for the media type “text/plain”. You can fix the issue by creating custom MediaTypeFormatter
in your application and then register your custom MediaTypeFormatter on Application_Start
method in your Global.asax.cs file. Brian explained this solution here.
I hope
that’ll solve your problem J
Comments
Post a Comment