Azure 网站 PHP API - PUT 和 DELETE 上不允许使用 405 方法

标签 azure web-config azure-web-app-service http-method

我正在使用 Azure 网站构建一个简单的 PHP Web 服务,但无法让它支持 PUT 和 DELETE http 方法。假设它必须进入 web.config 文件 - 我已经尝试了互联网上的一些选项,但它们似乎都不能正常工作。有什么想法吗?

这是当前的 web.config 文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
    </handlers>
    <security>
    </security>
    <directoryBrowse enabled="false" />
    <caching>
      <profiles>
        <add extension=".php" policy="DontCache" kernelCachePolicy="DontCache" />
        <add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00" />
      </profiles>
    </caching>
    <rewrite>
      <rules>
        <rule name="block favicon" stopProcessing="true">
          <match url="favicon\.ico" />
          <action type="CustomResponse" statusCode="404" subStatusCode="1"
          statusReason="The requested file favicon.ico was not found"
          statusDescription="The requested file favicon.ico was not found" />
        </rule>
        <rule name="Cols Rule" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
    <defaultDocument>
      <files>
        <remove value="index.php" />
        <add value="index.php" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

最佳答案

我没有看到您的 web.config 中添加了处理程序。我没有亲自测试过,但有人建议 PUT 和 DELETE 应该与 Windows Azure 网站一起使用,但是您需要通过 web.config 在 Windows Azure 网站上正确配置它们。

以下是您可以用来设置它的简单配置:

<configuration>
 <system.webServer>
    <handlers>
        <remove name="PHP53_via_FastCGI" />
        <add name="PHP53_via_FastCGI" path="*.php"
               verb="GET, PUT, POST, HEAD, DELETE" 
               modules="FastCgiModule" 
               scriptProcessor="D:\Program Files (x86)\PHP\v5.3\php-cgi.exe"
               resourceType="Either" requireAccess="Script" />
    </handlers>
 </system.webServer>
</configuration>

关于Azure 网站 PHP API - PUT 和 DELETE 上不允许使用 405 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15908381/

相关文章:

azure - 尝试使用 Azure 通知中心批量发送时出现 403 禁止

sql-server - sql server 驱动程序名称

asp.net - ASP.NET应用程序中用于开发和生产的不同配置文件

azure - 使用 ftp 访问 Azure 中的特定文件夹

Azure EventHub 高级吞吐量限制

wordpress - 如何使用 WordPress 配置 Windows Azure 进行 URL 重写?

sql - Azure ARM 模板 "VmAgentNotRunning"

c# - 配置文件标记为重复的异常包

azure - 什么决定了 Azure 中应用服务的出站 IP 地址?

azure - VSTS Azure 应用服务部署发布任务不更新文件