How do I enable PUT requests in Azure?

雨燕双飞 提交于 2019-11-26 22:08:05

问题


I'm building a REST API on Azure, but when I try to access an endpoint via the PUT method I get a HTTP 405 "Method Not Allowed" status along with an IIS error message:

The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.

How do I enable the PUT method, and other methods that may be blocked by default by Azure's default config settings?

I tried adding a web.config file to the root of my application with allowUnlisted set to true on the verbs element:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <verbs applyToWebDAV="false" allowUnlisted="true" />
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>

This changed nothing.

I'm an open source guy, so the world of IIS is very unfamiliar to me. Any help is appreciated.

Thanks!


回答1:


Add the following to the web.config in the system.webServer element:

<handlers>
  <remove name="PHP54_via_FastCGI" />
  <add name="PHP54_via_FastCGI" path="*.php" verb="GET, PUT, POST, HEAD, OPTIONS, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK" modules="FastCgiModule" scriptProcessor="D:\Program Files (x86)\PHP\v5.4\php-cgi.exe" resourceType="Either" requireAccess="Script" />
</handlers>

This works for the built in versions of PHP, the current default is PHP 5.4, but if you have selected PHP 5.3 or PHP 5.5 you will need to modify the path of the php-cgi handler.




回答2:


To complete the answer given by cory_flower you should change 54 by the version that is given,

Exemple: 7.2 gives:

<handlers>
  <remove name="PHP72_via_FastCGI" />
  <add name="PHP72_via_FastCGI" path="*.php" verb="GET, PUT, POST, HEAD, OPTIONS, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK" modules="FastCgiModule" scriptProcessor="D:\Program Files (x86)\PHP\v7.2\php-cgi.exe" resourceType="Either" requireAccess="Script" />
</handlers>

Pretty trivial but just for info

Update: fixed path




回答3:


Add this to your web.config/system.webServer:

<handlers>
  <remove name="ExtensionlessUrl-Integrated-4.0" />
  <add name="ExtensionlessUrl-Integrated-4.0"
       path="*."
       verb="GET,HEAD,POST,DEBUG,DELETE,PUT"
       type="System.Web.Handlers.TransferRequestHandler"
       preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

or instead of specifying what verbs are allowed, say verb="*" to allow all the verbs.



来源:https://stackoverflow.com/questions/25170826/how-do-i-enable-put-requests-in-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!