I wrote REST service using ASP.NET Web API. I'm trying to send HttpDelete request, however I get the following error:
405 - HTTP verb used to access this page is not allowed
I think I'm close to the solution, I found out that I should enable IIS remote management , go to Handler Mappings section and add DELETE verb to the appropriate position... but the problem is that there is a lots of different positions on the list... (sth like here: http://www.somacon.com/p126.php).
Which one should I edit? Few of them don't have extension, e.g. "ExtensionUrlHandler-Integrated-4.0" and I added DELETE verb to it, but it still doesn't work...
It was just a shot in the dark to modify that one, so should I modify different position? If so, which one? Or maybe is there anything more what I should do?
The same web service work perfectly fine on my local service, so I guess the problem is with the remote IIS...
Greetings
If it is IIS 8.0 check if HTTP Activation is enabled. Server manager -> IIS -> Manage (see right top) -> Add Roles and Features -> ... -> get to WCF configuration and then select HTTP Activation.
In our case, the problem was with federated signon between a .Net site and ADFS. When redirecting to the ADFS endpoint the
wctx
parameter needed all three parameters for theWSFederationAuthenticationModule.CreateSignInRequest
method:rm
,id
, andru
Thanks to Guillaume Raymond for the tip to check the URL parameters!
Besides all above solutions, check if you have the "
id
" or any custom defined parameter in theDELETE
method is matching the route config.If you hit with repeated 405 errors better reset the method signature to default as above and try.
The route config by default will look for
id
in the URL. So the parameter nameid
is important here unless you change the route config under theApp_Start
folder.You may change the data type of the
id
though.For example the method below should work just fine:
Note: Also ensure that you pass the data over the url not the data method that will carry the payload as body content.
Example:
Hope it helps.
If none of the above solutions solved your issue like in my case (still stuck with my RestClient module facing 405 ) try to request your Api with a tool like Postman or Fiddler. I mean the problem may be elsewhere like a bad formatted request.
I discover that my RestClient module was asking a 'Put' with an Id paremeter not well formatted :
instead of
Incidiously, bad formatted request returns 405 - Method Not Allowed (IIS 7.5)
You don't need to uninstall WebDAV, just add these lines to the web.config:
This error is coming from the staticfile handler -- which by default doesn't filter any verbs, but probably can only deal with HEAD and GET.
And this is because no other handler stepped up to the plate and said they could handle DELETE.
Since you are using the WEBAPI, which because of routing doesn't have files and therefore extensions, the following additions need to be added to your web.config file:
Obviously what is needed depends on classicmode vs integratedmode, and classicmode depends on bitness. In addition, the OPTIONS header has been added for CORS processing, but if you don't do CORS you don't need that.
FYI, your web.config is the local to the application (or application directory) version whose top level is applicationHost.config.