5

I've been through just about every article I can find, on SO and more. I've made changes to the Web.config to meet the answers as they all seem to point to removing the WebDAV module and handler.

However, I'm still getting the error:

405 Method Not Allowed

The requested resource does not support http method 'PUT'.

NOTE: this was originally just an MVC 4 project. I've added artifacts to support Web API. Seems like it's possible I may have missed something.

NOTE: the GET calls are working just fine from Angular.

Web API Route Config

configuration.Routes.MapHttpRoute(
    name: "Default API",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { action = "Get", id = RouteParameter.Optional },
    constraints: new { id = @"[\da-z-]{36}" });

configuration.Routes.MapHttpRoute(
    name: "Default API with Action",
    routeTemplate: "api/{controller}/{action}",
    defaults: new { action = "Get" });

var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
formatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();

Web.config

<modules runAllManagedModulesForAllRequests="true">
  <remove name="WebDAVModule" />
</modules>
<handlers accessPolicy="Read, Execute, Script">
  <remove name="WebDAV" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

PUT API Entry

public async Task<IHttpActionResult> Put([FromBody] EditUserViewModel viewModel)

Client Side

vm.model.$update(function () {
    $state.go(userStates.app);
});

Is it possible it's falling into the second route configuration? If so, how can I verify what route configuration .NET is trying to use?

Community
  • 1
  • 1
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
  • Possible duplicate of [ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8](http://stackoverflow.com/questions/10906411/asp-net-web-api-put-delete-verbs-not-allowed-iis-8) – BentOnCoding Dec 16 '15 at 21:46
  • I would create a Web.API app from scratch, recreate the problem and see if you can reproduce. It looks like you have done the correct webDAV config modifications. Like you said it's hard to tell if converting this from an mvc app caused some unseen pipeline issue. – BentOnCoding Dec 16 '15 at 21:48
  • Maybe I'm missing something here, but won't those routes both match, meaning that the first route will get hit? Is it possible that the first route that matches only supports GET? – Brendan Green Dec 16 '15 at 22:21
  • @BrendanGreen I was wondering the same thing, but it appears that's not the case. I'm not getting the error related to multiple matches. I got that after adding a new one and that error is very explicit. – Mike Perrenoud Dec 16 '15 at 22:22

2 Answers2

4

In the end it appears to be the fact that I was trying to complicate the routing table. I ended up rolling it back to this:

configuration.MapHttpAttributeRoutes();

configuration.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional });

Do take note to the fact that I added configuration.MapHttpAttributeRoutes(); as well.

After those two changes all is working well believe it or not. The Web.config looks like this:

<handlers>
  <remove name="ExtensionlessUrl-Integrated-4.0"/>
  <add name="ExtensionlessUrl-Integrated-4.0"
       path="*."
       verb="*"
       type="System.Web.Handlers.TransferRequestHandler"
       preCondition="integratedMode,runtimeVersionv4.0"
       responseBufferLimit="0" />
</handlers>
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
0

I struggled with this as well and found that I had to do a little bit more. Give this a try:

 <handlers>
  <remove name="OPTIONSVerbHandler" />
  <remove name="TRACEVerbHandler" />
  <!-- Fix Microsofts propensity to interfere with requests -->
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="SimpleHandlerFactory-ISAPI-2.0-64" />
  <remove name="SimpleHandlerFactory-ISAPI-2.0" />
  <remove name="SimpleHandlerFactory-Integrated" />
  <remove name="SimpleHandlerFactory-Integrated-4.0" />
  <remove name="SimpleHandlerFactory-ISAPI-4.0_64bit" />
  <remove name="SimpleHandlerFactory-ISAPI-4.0_32bit" />
  <!-- IISFIX: Now that we're ripped out everything related to ASP.net, put them back correctly.-->
  <add name="SimpleHandlerFactory-ISAPI-4.0_32bit" path="*.ashx" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="SimpleHandlerFactory-ISAPI-4.0_64bit" path="*.ashx" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
  <add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
  <add name="SimpleHandlerFactory-ISAPI-2.0" path="*.ashx" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" />
  <add name="SimpleHandlerFactory-ISAPI-2.0-64" path="*.ashx" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <!--IISFIX: WebDAV is also buggy, and interferes with client requests-->
  <remove name="WebDAV" />
</handlers>

John Fager
  • 452
  • 1
  • 4
  • 16