How to get PUT and DELETE verbs to work with WebAPI on IIS

后端 未结 3 1211
小蘑菇
小蘑菇 2020-12-18 10:16

I am using WebAPI PUT and DELETE methods to perform actions from my website via AJAX using jQuery. My server is Windows Server 2008 R2 with Plesk installed. POST and GET r

相关标签:
3条回答
  • 2020-12-18 10:42

    An extract from my web.config around the ExtensionlessUrlHandler-Integrated-4.0.

    Looking at the difference between yours and mine I don't have this section resourceType="Unspecified" requireAccess="Execute". I also use verb="*" that shouldn't make a difference but might be worth a try.

    Also note I do not have accessPolicy="Read, Execute, Script" attribute in the handlers section. I also do not remove WebDAV.

    <system.webServer>
        <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>
    

    Possible answer from: https://stackoverflow.com/a/18458139/1398425

    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*" />
          <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE" />
          <add name="Access-Control-Allow-Headers" value="Content-Type" />
        </customHeaders>
      </httpProtocol>
      <modules runAllManagedModulesForAllRequests="false">
        <remove name="WebDAVModule" />
      </modules>
    
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <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" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      </handlers>
    </system.webServer>
    
    0 讨论(0)
  • 2020-12-18 10:55

    Actually removing WebDAV from my server caused the application to return a 503 Service Unavailable Error message, so I re-installed it.

    I was able to fix this by disabling WebDAV for the individual application pool, this stopped the 'bad module' error.

    Disable WebDAV for Individual App Pool:

    1. Click the affected web site in IIS
    2. Find WebDAV Authoring Tools in the list
    3. Click to open it
    4. Click Disable WebDAV in the top right.

    Ta daaaa!

    This link is where I found the instructions but it's not very clear.

    0 讨论(0)
  • 2020-12-18 10:57

    For myself it wasn't enough to do everything @Luke was doing. I had to also go into my Programs and Features and and under Internet Information Services > World Wide Web Services > Common HTTP Features turn off WebDAV Publishing

    That then fixed it for me.

    0 讨论(0)
提交回复
热议问题