0

Is it possible to accept PUT http requests in ASP.NET Web Forms? eg www.test.com/Users/12345 I can accept GET and POST no problem. Using rewrite in my web.config I can forward the request URL to my .aspx page even though it has no extension. However I just get a HTTP Error 405.0 - Method Not Allowed error. Just wondering if this is an IIS setup issue or whether ASP.NET just cant accept PUT http requests. I have applied all the fixes regarding disabling WebDAV etc, but it still doesn't work.

mason
  • 31,774
  • 10
  • 77
  • 121
Nick Hill
  • 1
  • 1
  • Does this help: https://stackoverflow.com/questions/12440277/how-do-i-enable-http-put-and-delete-for-asp-net-mvc-in-iis – Matt Evans Mar 10 '21 at 13:36
  • @MattEvans This is Classic ASP, not ASP.NET MVC – squillman Mar 10 '21 at 13:36
  • 1
    Have a look at this in which Scott Hanselman suggests using the X-HTTP-Method-Override header in a POST request. The article centers around doing this in WebAPI, but you should be able to replicate the technique in classic ASP by reading the request headers. It might be a bit clunky on the backend though.... https://www.hanselman.com/blog/http-put-or-delete-not-allowed-use-xhttpmethodoverride-for-your-rest-service-with-aspnet-web-api – squillman Mar 10 '21 at 13:37
  • @squillman it depends what you mean by 'Classic' it actually looks like Webforms, not old school .asp . You still configure handlers and verbs in webforms via IIS – Matt Evans Mar 10 '21 at 13:43
  • yes its webforms not old school asp.. – Nick Hill Mar 10 '21 at 14:04
  • thanks Matt / @squillman - just to reiterate Im not after solutions that use MVC or Web API – Nick Hill Mar 10 '21 at 14:08
  • Please don't call it classic. That's something completely different. You're using Web Forms. Call it that. – mason Mar 10 '21 at 14:14
  • Are you positive the 405 error is coming from IIS? Do you have any networking infrastructure in between, such as load balancers? Did you check the request filtering settings in IIS to make sure PUT is an allowed verb? If you create a generic handler (*.ashx) and try to PUT to it, does that work? – mason Mar 10 '21 at 14:17

1 Answers1

0

Ok the solution was to use a generic handler (*.ashx) and put the following in web.config:

<system.webServer>
      <handlers>
            <remove name="SimpleHandlerFactory-ISAPI-4.0_32bit" />
            <remove name="SimpleHandlerFactory-ISAPI-4.0_64bit" />
            <add name="SimpleHandlerFactory-ISAPI-4.0_64bit" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Either" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
            <add name="SimpleHandlerFactory-ISAPI-4.0_32bit" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Either" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />            
      </handlers>
</system.webServer>

Could not get it to work with .aspx files at all, even if the correct verbs are setup for the handlers. Thanks to @mason for pointing me in the right direction!

EDIT: In addition the application pool must be running in classic mode, not integrated. Thanks Microsoft for stealing 3 days of my time working out your unfixed bugs!

Nick Hill
  • 1
  • 1
  • OK so this works on my dev box (win 10, vs2017, iis10) but does not work on my production server (win 2012 R2 IIS8.5). HTTP Error 405.0 - Method Not Allowed. PUT requests against my generic handler .ashx file appear to be handled by the StaticFile handler - which is obviously incorrect.. – Nick Hill Mar 11 '21 at 12:09
  • Found the problem - the application pool must be running in classic not integrated mode. – Nick Hill Mar 11 '21 at 14:35