Thursday, 12 July 2012

Method Not Allowed 405 on IIS7 Website eg PUT, DELETE etc

If you are working with a .net MVC4 WebApi project that needs to provide CRUD capabilities then your the standard Http Methods your site will need to accept are GET, POST, PUT, DELETE.


I had trouble getting my site to accept PUT and DELETE methods when hosting my site locally with IIS7. I am hosting the application under its own website, this lets me change the settings for the particular site using the IIS7 interface. Here are the steps I took to correct the problem:


Begin in IIS7 by highlighting your website, then choosing Handler Mappings from the available options:





Then select WebDAV from the list of Mappings.



Click Request Restrictions.


Then switch to the Verbs tab and highlight All Verbs.


Restart the application in IIS and hey presto! PUT and DELETE enabled (as well as all HTTP methods). If you want to more conservative about which methods are supported then use the option beneath All Verbs.This results in the changes to your Web.config. Inside your <system.web> section goes this snippet: (You don't actually have to add this - IIS7 will have added this itself)

<handlers>
  <remove name="WebDAV" />
  <add name="WebDAV" path="*" verb="*" modules="WebDAVModule" resourceType="Unspecified" requireAccess="None" />
</handlers>

Hope this will help someone out!

P.s. I found WFetch to be quite a useful tool in debugging http requests.







18 comments:

  1. http://betimdrenica.wordpress.com/2013/02/05/web-api-on-iis-8-0-405-method-not-allowed-for-put/

    ReplyDelete
  2. Fixed it for me. Thanks!

    ReplyDelete
  3. Thanks, the screenshots really helped!

    ReplyDelete
  4. Thanks - the screenshots were tremendously useful.

    ReplyDelete
  5. This is not the best way. See here: http://stackoverflow.com/questions/6739124/iis-7-5-enable-put-and-delete-for-restful-service-extensionless

    ReplyDelete
  6. I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy.
    video and blog marketing

    ReplyDelete
  7. Thank u so much ... I need it :) it works for me after a lot of search.

    ReplyDelete
  8. Great help ! thanks for sharing.

    ReplyDelete