IIS 7.5 + 为RESTFul 服务启用PUT 和DELETE,无扩展 [英] IIS 7.5 + enable PUT and DELETE for RESTFul service, extensionless

查看:28
本文介绍了IIS 7.5 + 为RESTFul 服务启用PUT 和DELETE,无扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 IIS 7.5 如何处理 POST 和 PUT 请求.

i am trying to understand how IIS 7.5 handles POST and PUT request.

我正在使用 OpenRasta 框架编写 RESTful 服务.POST 操作没有任何问题,但相同 URL 的 PUT 操作没有任何问题.它返回如下错误

I am writing a RESTful service using OpenRasta framework. The POST operation works without any problem, but the PUT operation for the same URL does not. It returns error like the following

Detailed Error Information
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002

网址如下http://localhost/MyService/Resource.Something.manifest"

the url is like this following "http://localhost/MyService/Resource.Something.manifest"

同样的设置在 Visual Studio 开发 IIS 中也能正常工作.

Same setup works fine in visual studio development IIS.

解决方案

基本上默认的 ExtensionlessUrlHandler 不接受 PUT 和 DELETE 动词.只需要添加它们.

Basically the default ExtensionlessUrlHandler does not accept PUT and DELETE verb. Just need to add them.

<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="IsapiModule" scriptProcessor="C:WindowsMicrosoft.NETFramework64v4.0.30319aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />

推荐答案

为了让 PUT 和 DELETE 被 IIS 7.5 接受,用于 PHP 5.4 快速 CGI 驱动的 REST API,我不得不禁用 WebDAV 模块.否则,WebDAV 模块会使用 PUT 或 DELETE 干预 HTTP 请求.然而,让这项工作有点混乱,我可能错过了一些步骤或以其他顺序完成.

To get PUT and DELETE to be accepted by IIS 7.5 for a PHP 5.4 fast-CGI driven REST API I had to disable the WebDAV-module. Otherwise the WebDAV module intervenes the HTTP requests using PUT or DELETE. To get this working was however a bit confusing and I might have missed some steps or done it in another order.

这些行作为 元素的子元素放置在应用程序根目录的 web.config 中.

These lines are placed as children of the <system.webServer>-element in web.config in the application root.

<modules>
    <remove name="WebDAVModule" />
</modules>
<handlers>
    <remove name="WebDAV" />
</handlers>

希望这可以避免一些挫折.似乎服务器的默认设置是接受任何未列出的 HTTP 动词 - 请参阅 请求过滤下的设置 ->HTTP 动词 ->编辑功能设置.可以考虑明确添加允许的动词.可以指定允许的动词附加到此代码段,也可以作为 的子项.

Hopes this might spare some frustration. It seems like the default setting for the server is to accept any HTTP verb not listed - see settings under Request filtering -> HTTP Verbs -> Edit feature Settings. One may consider to explicitly add the VERBS that are to be allowed. The verbs allowed may be specified appending this snippet, also as a child of <system.webServer>.

    <security>
        <requestFiltering>
            <verbs allowUnlisted="false">
                <add verb="GET" allowed="true" />
                <add verb="POST" allowed="true" />
                <add verb="DELETE" allowed="true" />
                <add verb="PUT" allowed="true" />
            </verbs>
        </requestFiltering>
    </security>

在客户端机器上,可以从这里卸载 WebDAV 模块:

On a client machine one can uninstall the WebDAV module from here:

Control Panel -> Uninstall Program -> Turn Windows features on or off -> IIS -> World Wide Web Services -> Common HTTP feautre -> WebDAV Publishing

使其工作的最后一种方法是编辑 C:WindowsSystem32inetsrvconfig 中的 applicationhost.config.内-><handlers> 您将看到一个只有 verb="GET,HEAD,POST 的 php 条目 - 修改它以添加您需要的动词,例如:

The last measure to get it working was by editing applicationhost.config found in C:WindowsSystem32inetsrvconfig. Within <system.webServer> -> <handlers> you will see a php entry that has just verb="GET,HEAD,POST - amend it to add the verbs you require, e.g.:

<add name="PHP54_via_FastCGI" path="*.php" verb="GET,HEAD,PUT,DELETE,POST"/>
                                                                 |
                                                                 |
                                                                 |
append verbs here  ----------------------------------------------|

这篇关于IIS 7.5 + 为RESTFul 服务启用PUT 和DELETE,无扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆