title: HTTP Error 405.0 - Method Not Allowed in IIS Express
body: <p>When issuing a perfectly cromulent verb to a local IIS Express web-site under Visual Studio 2013:</p>
  
  <pre><code>CROMULENT http://localhost:7579/Handler.ashx HTTP/1.1
  Host: localhost:7579
  </code></pre>
  
  <p>the server responds with the error:</p>
  
  <pre><code>HTTP/1.1 405 Method Not Allowed
  Allow: GET, HEAD, OPTIONS, TRACE
  </code></pre>
  
  <p>That is a request to a <em>"generic handler"</em> <em>(i.e. <code>.ashx</code>)</em>. If if i try again to a <em>static</em> resource:</p>
  
  <pre><code>SCHWIFTY http://localhost:7579/Default.htm HTTP/1.1
  Host: localhost:7579
  </code></pre>
  
  <p>the server responds with the error:</p>
  
  <pre><code>HTTP/1.1 405 Method Not Allowed
  Allow: GET, HEAD, OPTIONS, TRACE
  </code></pre>
  
  <p>This is all by way to trying to use HTTP verbs:</p>
  
  <pre><code>DELETE http://localhost:7579/Handler.ashx HTTP/1.1
  Host: localhost:7579
  
  HTTP/1.1 405 Method Not Allowed
  Allow: GET, HEAD, OPTIONS, TRACE
  
  PUThttp://localhost:7579/Handler.ashx HTTP/1.1
  Host: localhost:7579
  
  HTTP/1.1 405 Method Not Allowed
  Allow: GET, HEAD, OPTIONS, TRACE
  </code></pre>
  
  <p>This question has been asked to death, sometimes by me. But nobody has ever come up with a solution. </p>
  
  <h2>&lt;/Question&gt;</h2>
  
  <p><strong>Microsoft's Bug</strong></p>
  
  <p>The problem, fundamentally, is that Microsoft ships IIS and IISExpress broken by default. Rather than handling HTTP verbs, as a web-server is required to do, they don't handle verbs.</p>
  
  <p>This can most easily be seen when managing full IIS running on Windows Server. Pick any of the built-in handlers (e.g. the cshtml handler), and you can see that someone thought it would be <em>hilarious</em> if it only worked with <code>GET</code>, <code>HEAD</code>, <code>POST</code>, and <code>DEBUG</code> verbs:</p>
  
  <p><a href="https://i.stack.imgur.com/9jpkG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9jpkG.png" alt="enter image description here"></a></p>
  
  <p>rather than correctly implementing support for HTTP in an HTTP server.</p>
  
  <p>The question becomes:</p>
  
  <ul>
  <li>why <strong><em>exactly</em></strong> doesn't it work</li>
  <li>how <strong><em>exactly</em></strong> to fix it</li>
  <li>how to fix it in <strong><em>IIS Express</em></strong> (without any management tools)</li>
  <li><strong><em>why</em></strong> it continues to be shipped, year after year, broken </li>
  </ul>
  
  <h2>Question 1. Why doesn't it work?</h2>
  
  <p>The first question is why doesn't it work. Let's look at an IIS server where we've removed every handler except the basic <strong>Static</strong> file handler:</p>
  
  <p><a href="https://i.stack.imgur.com/dlZlX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dlZlX.png" alt="enter image description here"></a></p>
  
  <p>The handler is configured to all <em>all</em> verbs:</p>
  
  <p><a href="https://i.stack.imgur.com/corC2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/corC2.png" alt="enter image description here"></a></p>
  
  <p>The only handler left is set to allow <strong>any</strong> verb. Yet if we issue a request to the web server we get the error:</p>
  
  <pre><code>DELETE http://scratch.avatopia.com/ HTTP/1.1
  Host: scratch.avatopia.com
  
  HTTP/1.1 405 Method Not Allowed
  Allow: GET, HEAD, OPTIONS, TRACE
  Server: Microsoft-IIS/7.5
  </code></pre>
  
  <blockquote>
    <p>Why is this happening?</p>
  </blockquote>
  
  <p>Why didn't it work? Where is the configuration option that says:</p>
  
  <ul>
  <li><code>GET</code></li>
  <li><code>HEAD</code></li>
  <li><code>OPTIONS</code></li>
  <li><code>TRACE</code></li>
  </ul>
  
  <p>because the server itself is saying those are the only supported verbs.</p>
  
  <p>Yet if we change it to a <code>GET</code> it works fine:</p>
  
  <pre><code>GET http://scratch.avatopia.com/ HTTP/1.1
  User-Agent: Fiddler
  Host: scratch.avatopia.com
  
  HTTP/1.1 200 OK
  Content-Type: text/html
  </code></pre>
  
  <h2>Question 2. How to fix it?</h2>
  
  <p>The common wisdom is to remove <strong>WebDAV</strong>. Nobody knows what WebDAV is, how it could be a problem, why it is a problem, or why it exists if it only causes problems. WebDAV can be removed as a handler from the IIS administration user interface:</p>
  
  <p><a href="https://i.stack.imgur.com/AJR9O.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AJR9O.png" alt="enter image description here"></a></p>
  
  <p>which is <strong>identical</strong> to adding a <code>remove</code> entry from the <code>handlers</code> section in <code>web.config</code> (the UI itself adds the entry to web.config for you):</p>
  
  <pre><code>&lt;system.webServer&gt;
      &lt;handlers&gt;
          &lt;remove name="WebDAV" /&gt;
      &lt;/handlers&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>Except this doesn't work. So how do we <em>fix</em> it?</p>
  
  <p>Starting with IIS it seems that WebDAV has become even more of a virus. Rather than simply disabling it as a handler, <a href="https://stackoverflow.com/questions/10906411/asp-net-web-api-put-delete-verbs-not-allowed-iis-8">you have to completely install or remove it as a module</a>:</p>
  
  <pre><code>&lt;system.webServer&gt;
    &lt;modules&gt;
      &lt;remove name="WebDAVModule" /&gt;
    &lt;/modules&gt;
    &lt;handlers&gt;
      &lt;remove name="WebDAV" /&gt;
    &lt;/handlers&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>That sounds like a reason idea, except in my test case, on IIS 7.5, WebDAV is both not installed, and removed as a module:</p>
  
  <pre><code>HTTP/1.1 405 Method Not Allowed
  Allow: GET, HEAD, OPTIONS, TRACE
  Server: Microsoft-IIS/7.5
  X-Powered-By: ASP.NET
  Date: Tue, 10 May 2016 19:19:42 GMT
  Content-Length: 0
  </code></pre>
  
  <p>So, if we can figure out how to solve the problem, we can answer question number two.</p>
  
  <h2>Question 3. How to fix it in IIS Express</h2>
  
  <p>Starting with Visual Studio 2013<sup>1</sup>, Visual Studio no longer uses a mini web-server called Cassini. It uses a portable install of IIS Express itself (i.e. IIS Express Windows feature doesn't need to be installed).</p>
  
  <p>Most of the above fix (attempts) (fail) in IIS. But nobody has dealt with them in IIS Express of Visual Studio 2013 (which is how this question is different from any others).</p>
  
  <h2>Question 4. Why does this keep happening?</h2>
  
  <p>It's been over 15 years, and this still keeps happening. There must be a <em>good</em> reason why IIS does not function as a web-server. But what is it? I've not been able to find any knowledge base article, or blog post, explaining why the IIS team refuses to function correctly.</p>
  
  <h2>Bonus Reading</h2>
  
  <ul>
  <li>The most popular Stackoverflow question for this problem: <a href="https://stackoverflow.com/questions/10906411/asp-net-web-api-put-delete-verbs-not-allowed-iis-8">ASP.NET Web API - PUT &amp; DELETE Verbs Not Allowed - IIS 8</a></li>
  </ul>
  
  <h2>Research Effort</h2>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/35955747/http-error-405-0-method-not-allowed-with-post">HTTP Error 405.0 - Method Not Allowed, with POST</a> <em>(no answer, php)</em></li>
  <li><a href="https://stackoverflow.com/questions/11238585/http-error-405-0-method-not-allowed">HTTP Error 405.0 - Method Not Allowed</a> <em>(no answer)</em></li>
  <li><a href="https://stackoverflow.com/questions/19446604/post-verb-not-allowed">POST verb not allowed</a> <em>(php)</em></li>
  <li><a href="https://stackoverflow.com/questions/34019130/http-error-405-0-method-not-allowed-in-asp-net-mvc5">HTTP Error 405.0 - Method Not Allowed in ASP.net MVC5</a> <em>(no answer, mvc)</em></li>
  <li><a href="https://stackoverflow.com/questions/35363032/jquery-file-uploader-error-405-iis8-5">JQuery File Uploader = error 405 IIS8.5</a> <em>(jquery no answer)</em></li>
  <li><a href="https://stackoverflow.com/questions/36629067/iis-7-5-405-method-not-allowed-for-put-from-staticfilemodule">IIS 7.5 405 Method Not Allowed for PUT from StaticFileModule</a> <em>(no answer, static module, iis)</em></li>
  <li><a href="https://stackoverflow.com/questions/5238080/the-http-verb-post-used-to-access-path-is-not-allowed">The HTTP verb POST used to access path is not allowed</a> <em>("don't use verbs")</em></li>
  <li><a href="https://stackoverflow.com/questions/26410041/http-error-405-method-not-allowed-error-with-web-api">http error 405 method not allowed error with web.API</a> <em>(uninstall WebDAV; already isn't)</em></li>
  <li><a href="https://stackoverflow.com/questions/8966866/handling-perl-iis-7-5">Handling Perl IIS 7.5</a> <em>(perl)</em></li>
  <li><a href="https://stackoverflow.com/questions/9088352/http-error-405-0-method-not-allowed-using-jquery-ajax-get">HTTP Error 405.0 - Method Not Allowed using Jquery ajax get</a> <em>(ajax)</em></li>
  <li><a href="https://stackoverflow.com/questions/1400210/what-causes-an-http-405-invalid-method-http-verb-error-when-posting-a-form-t">What causes an HTTP 405 &quot;invalid method (HTTP verb)&quot; error when POSTing a form to PHP on IIS?</a> <em>(iis6, ftp, php)</em></li>
  <li><a href="http://forums.asp.net/t/1648594.aspx" rel="noreferrer">http://forums.asp.net/t/1648594.aspx</a> <em>("have you tried pinging your computer")</em></li>
  <li><a href="https://stackoverflow.com/questions/31483355/angular-resource-post-put-to-webapi-405-method-not-allowed">Angular $resource POST/PUT to WebAPI 405 Method Not Allowed</a> <em>(try removing WebDAV handlder and WebDAV module)</em></li>
  <li><a href="https://stackoverflow.com/questions/29519201/http-error-405-0-method-not-allowed-iis-7-5-module-staticfilemodule">Http Error 405.0 - method not allowed iis 7.5 module staticfilemodule</a> <em>(no solution)</em></li>
  <li><a href="https://stackoverflow.com/questions/3389309/unable-to-set-up-webdav-with-iis-7">Unable to set up WebDAV with IIS 7</a> *(trying to <em>setup</em> webdav)*</li>
  <li><a href="https://stackoverflow.com/questions/24777466/android-soap-request-is-returning-http-response-405">Android SOAP request is returning HTTP Response 405</a> <em>(no solution)</em></li>
  <li><a href="https://stackoverflow.com/questions/10930742/wcf-service-doesnt-allow-post">wcf service doesn&#39;t allow POST</a> <em>(wcf)</em></li>
  <li><a href="https://stackoverflow.com/questions/15619075/webapi-delete-not-working-405-method-not-allowed">WebAPI Delete not working - 405 Method Not Allowed</a> <em>(WebAPI; remove WebDAV)</em></li>
  </ul>