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

查看:547
本文介绍了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:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />


推荐答案

让IIS 7.5接受PUT和DELETE对于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.

这些行被放置为<$ c $的子项c>< system.webServer> - 应用程序根目录中 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动词 - >编辑功能设置。可以考虑明确添加要允许的VERBS。可以指定允许的动词附加此片段,也作为< system.webServer> 的子元素。

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

使其工作的最后一项措施是编辑 applicationhost.config C:\ Windows \ System32 \inetsrv \ config 中找到。在这里我添加了我需要的动词:

The last measure to get it working was by editing applicationhost.config found in C:\Windows\System32\inetsrv\config. Here I added the verbs I needed:

<add name="PHP54_via_FastCGI" path="*.php" 
     verb="GET,HEAD,PUT,DELETE,POST" 
     modules="FastCgiModule" 
     scriptProcessor="C:\Program Files (x86)\PHP\v5.4\php-cgi.exe" 
     resourceType="Either" />

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

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