HTTP Error 405.0 – Method Not Allowed – REST Service
I was testing a REST service that another developer had coded and hosting it in IIS7, when ever a POST or PUT call was made. I would get the 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. This took a fair bit of time to track down a the problem, so I thought it would be worth mentioning. There are a couple of things I had to do to fix this issue.
Possible Fix 1
As I had recently had a re install, when I installed IIS I just selected everything. It turns out WebDAV Publishing will stop PUT/Post methods from working.
Go to Control Panel > Programs > Turn Windows Features on or off . Then expand Internet Information Services > World Wide Web Services > Common HTTP Features and then make sure WebDAV Publishing is not ticked. If it is, unselect it, click OK and reboot. Its more than likely you don’t even need WebDAV, but if you are not sure sure what it is, you can find out here.
Another possible cause is a lack of Handler Mappings. If you look in you IIS Handler Mappings and do not have JSON listed, this could be the issue. Just try the fix below…
- Go to IIS (Internet Information Services)
- Select the computer name at the root of the tree.
- Select Handler Mappings.
- From the Mappings screen, select the Add Script Map button in the right hand panel.
- Enter *.json as the Request path.
- Enter c:\WINDOWS\System32\inetsrv\asp.dll as the Executable.
- Enter JSON as the Name.
- Click OK, it might be worth restarting IIS at this stage.