Error 405

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.

IIS ConfigPossible Fix 2

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…

  1. Go to IIS (Internet Information Services)
  2. Select the computer name at the root of the tree.
  3. Select Handler Mappings.
  4. From the Mappings screen, select the Add Script Map button in the right hand panel.
  5. Enter *.json as the Request path.
  6. Enter c:\WINDOWS\System32\inetsrv\asp.dll as the Executable.
  7. Enter JSON as the Name.
  8. Click OK, it might be worth restarting IIS at this stage.