Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PUT and DELETE returns 404 for asp.net webapi in Windows 2008 Server IIS 7 and 7.5

I run into 500 - Internal Server Error when PUT/DELETE with windows 2008 server IIS. The response I get is:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>500 - Internal server error.</title>
<style type="text/css">
<!--
Formatting 
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
 <div class="content-container"><fieldset>
  <h2>500 - Internal server error.</h2>
  <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>
 </fieldset></div>
</div>
</body>
</html>

When I check my custom logs of my WebAPI I find that the call has not even hit the service.

My earlier experience was getting 404 - Not Found for PUT and DELETE and this behavior was consistent across Win7 and Win 2008 Server. For that I found this fix:

I applied the fix and PUT/DELETE works on windows 7. But after that when deployed the same service on IIS 7 in win2008 server I do not get 400. But I get "500 - Internal Server Error" from IIS or something even before that.

The same code works perfectly on windows 7 (IIS 7.5).

Any clues on resolution of such issues?

Edited Aug 29, 2012:

The issue of 500-Internal Server Error is detected by enabling fault-tracing in IIS7. The fix is this configuration.

<modules runAllManagedModulesForAllRequests="true">
  <remove name="WebDAVModule" />
</modules>
<handlers>
  <remove name="WebDAV" />
</handlers>

Basically we need to remove "WebDAVModule" from modules and also remove "WebDAV" from Handlers. But now I am back to my old issue of 404-Not Found. Now even after having the below configuration i cannot get PUT/DELETE to work:

  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />

Unusually the same web application works perfectly on hosted separately (not under default web site) on the same system same IIS. So I suspect this is due to some parent website configuration which filters PUT/DELETE requests.

Any ideas on the same?

like image 767
Sando Avatar asked Aug 27 '12 04:08

Sando


1 Answers

After agonizing over a very similar problem, I came upon this solution: http://www.iis.net/configreference/system.webserver/security/requestfiltering/verbs

Using the Request Filtering settings, I was able to globally allow the PUT and DELETE verbs in IIS, which solved my problem. It ended my nightmare of 404.6 errors. (btw, I did not have webDAV installed and did add the verbs to the ExtensionlessUrlHandler)

Hopefully this info can save someone some time.

like image 190
Neil S Avatar answered Sep 18 '22 11:09

Neil S