问题描述
如何让webapp 支持 delete 方法? 在不修改设置的情况下,调用DELETE方法出现405错误 - 方法不被允许
问题解决
基于当前App Service在Windows的环境中运行,所以可以使用配置IIS的方式在web.config中对Delete方法进行允许访问,正确的设置如下:
<configuration>
<system.webServer>
<security>
<requestFiltering>
<verbs applyToWebDAV="false">
<add verb=" DELETE" allowed=" true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
</configuration>
注:如果App Service中不包含web.config,可以进入Kudu站点( https://<your site name>.scm.chinacloudsites.cn/DebugConsole )创建,或者在您的项目文件根目录中创建后一起部署到App Service
如是PHP项目应用,文件中需要加上PHP Handler 设置(以PHP 7.3版本举例,需根据实际情况修改):
<configuration>
<system.webServer>
<security>
<requestFiltering>
<verbs applyToWebDAV="false">
<add verb=" DELETE" allowed=" true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
<handlers>
<remove name="PHP73x86_via_FastCGI" />
<!-- We instruct to delete the existing handler with that name -->
<add name="PHP73x86_via_FastCGI" path="*.php" verb="GET,HEAD,POST,DELETE" modules="FastCgiModule" scriptProcessor="D:\Program Files (x86)\PHP\v7.3\php-cgi.exe" resourceType="Either" />
<!-- We give the new values for the handler. It is basically the old handler but we added the DELETE method to the verbs -->
</handlers>
</configuration>
参考资料
拒绝HTTP请求方法的示例(Configuration Sample):https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/verbs/#configuration-sample
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!