3

I am attempting to publish code to my company test web server and I'm getting a multitude of errors returned from IIS when attempting to call any methods using the PUT or DELETE verb. I've researched this particular issue, and all of the results that I've attempted either do nothing, or generate a new error. When I try with the default system.webServer configuration I receive the general 405 method not allowed error, here's that portion of the web.config:

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>

From digging through Google and several stack articles, the majority of accepted answer specify to remove WebDAV through the web config file, which I've done, and here's that updated code:

<system.webServer>
  <modules>
    <remove name="WebDAVModule" />
  </modules
  <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="WebDAV" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>

When I try using just removing the WebDAV handler, I continue to get the 405 method not allowed error, but as soon as I remove the WebDAVModule, my error becomes a 500 Internal Server Error, and viewing from the server doesn't actually give me any further information.

I've also attempted suggestions revolving around removing and adding the "ExtensionlessUrlHandler-ISAPI-4.0_32bit" & "ExtensionlessUrlHandler-ISAPI-4.0_64bit" handlers, with the same results (405 when don't remove the WebDAVModule or 500 when I do remove it).

Here's the methods on my WebApi controller that I'm attempting to call, maybe this is the problem, though it works just fine in my development environment:

public string PutRegistrationBatch(RegistrationBatch Model) {
  // Code to save the model to our database
}
public string DeleteRegistrationBatch(RegistrationBatch Model) {
  // Code to delete the item from the database
}

UPDATE

I ran a trace on the application and I'm seeing GET and POST commands get through to the site, however none of the PUT or DELETE commands get through to the site:

  1. 1/10/2017 1:22:41 PM /api/RegistrationBatch/ 200 GET
  2. 1/10/2017 1:22:55 PM /api/RegistrationBatch/ 200 POST

It seems as though the PUT and DELETE commands are being filtered out and refused at the host level and never making into my application.

UPDATE

It seems that WebDAV is the underlying issue, but we run a web service that utilizes this technology, so removing it is not an option until we can update that service. In the mean time, I've found that a work around outlined by Scott Hanselman here (http://www.hanselman.com/blog/HTTPPUTOrDELETENotAllowedUseXHTTPMethodOverrideForYourRESTServiceWithASPNETWebAPI.aspx) allows for me to send PUT and DELETE requests as a POST request.

I wouldn't suggest that is is an answer to the problem, but it at least allows me to work around the problem until such a time as we can uninstall WebDAV and hopefully that will allow my Web Api 2 application(s) to work properly.

  • Do you have access to application logs? Internal server error could mean that your application logic throws an exception (e.g. authorization error to database). – Botond Botos Jan 10 '17 at 14:40
  • I had one of our server admins check the event logs on the server and nothing is being logged. – Joshua McCrea Jan 10 '17 at 14:42
  • Does your application have tracing functionality? I'd turn it on to be sure that the request gets handed over to your application. – Botond Botos Jan 10 '17 at 14:46
  • I enabled trace through the web.config, but no trace file was generated for the application – Joshua McCrea Jan 10 '17 at 14:57
  • This could mean that tracing is not installed/enabled for the site. We still cannot be sure where is the error coming from. I suggest adding application level tracing/logging to your application. – Botond Botos Jan 10 '17 at 15:19
  • I updated my edit, I was a bit ignorant of where to find the trace information, I found it though as mentioned at the bottom of the post above. – Joshua McCrea Jan 10 '17 at 15:27
  • You need to apply the `[HttpPut]` and `[HttpDelete]` attributes on the actions – Nkosi Jan 11 '17 at 01:49

3 Answers3

0

You need to apply the [HttpPut] and [HttpDelete] attributes on the respective actions

[HttpPut]
public string PutRegistrationBatch(RegistrationBatch Model) { ... }

[HttpDelete]
public string DeleteRegistrationBatch(RegistrationBatch Model) { ... }

And in the config file you should also try to use the specific verbs you want to allow

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Nkosi
  • 235,767
  • 35
  • 427
  • 472
0

If you have the WebDAV IIS feature installed, it can cause conflicts with Put, Delete, and Patch requests (maybe more... can't remember). You can either uninstall the feature server-wide or manually remove the HttpModule and HttpHandlers from the system.webServer element to target this specific application. See https://stackoverflow.com/a/26003440/179223

Community
  • 1
  • 1
scottt732
  • 3,877
  • 2
  • 21
  • 23
  • WebDAV is installed on the server for another application, however as I mentioned in my original post, removing it through the web.config actually causes further problems. From what I can tell, WebDAV is not listed in the handlers or modules for my applications, but it is listed on the server level (and default web site), my guess is that I need to remove it from the default web site as the calls aren't getting to my application. – Joshua McCrea Jan 11 '17 at 13:37
  • Is your application pool configured in Integrated or Classic pipeline mode? The reason I ask is because removing modules & handlers is a little different (it goes in system.web somewhere, not system.webServer in classic mode). Also check if you have request filtering setup (either via the IIS Management Console or by looking for `//` in your web.config. Also check `C:\Windows\System32\inetsrv\config\applicationHost.config` and `C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config` (tweak the path for bitness/version). – scottt732 Jan 11 '17 at 16:42
  • The application pool for my application is configured in Integrated mode. There's no request filtering set up of HTTP Verbs, it's just set to allow everything unless otherwise stated in the list. The Default Web Site at the parent level is configured in classic mode though, not sure if that makes any difference. I did notice earlier that none of the ExtensionlessUrlHandler handlers were mapped on the Default Web Site, and the Integrated-4.0 was disabled at the server level. I enabled it at the server level, but still had no effect. – Joshua McCrea Jan 11 '17 at 17:03
  • When ExtensionlessUrlHandler isn't working, I think it typically even affects GET requests. If you add a GET request to the same controller you're having trouble with, can you confirm that it's routing properly? Try installing RouteDebugger to verify routing is working. The 405 is WebDav. Is the 500 w/WebDav disabled a YSOD or an IIS 500 page? If it's the latter, your request isn't making it into your app. Setup event handlers for every event in global.asax and set a breakpoint on something in each event handler (call GetHashCode or something w/no side effects & set a breakpoint on all) – scottt732 Jan 11 '17 at 19:23
  • All of my POST and GET requests work across my application, but none of the PUT or DELETE requests do. The 500 is a IIS 500 page, I know it's not getting to my application as I've got tracing enabled and I don't see those requests. In regards to debugging, I don't have access to Visual Studio on our web servers, if there are no further suggestions, I'll bring this up with our network team to see if we can get it installed for troubleshooting this. – Joshua McCrea Jan 11 '17 at 19:50
  • Is the web application directly above yours the one that's configured to require WebDAV? In other words, is Default Web Site/YourApp where Default Web Site (DWS) has WebDAV enabled/required? If so, that may be causing conflicts. You may want to use a location tag in DWS to include it at that path only or exclude it for paths matching YourApp. If WebDAV is about adding & removing content, at the DWS-level it might get confused as to whether PUT YourApp/File is a request to DWS to create YourApp/File or whether to allow IIS to route the request to YourApp. – scottt732 Jan 13 '17 at 10:59
0

I remember getting into similar ditch sometime ago. Eventually this worked for me.

Reset all module configurations of 'Default Web Site' and your website to default values in IIS. You can do this by 1. Select your website, double click "Modules" 2. Click on "Revert to Parent" link under Actions panel on right side

Use the following into your Web.config

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" runManagedModulesForWebDavRequests="true">
      <remove name="WebDAVModule" />
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
Rajiv
  • 1,426
  • 14
  • 21