IIS 7.5 +为 RESTFul 服务启用 PUT 和 DELETE,无扩展
我试图了解 IIS 7.5 如何处理 POST 和 PUT 请求。
我正在使用 OpenRasta 框架编写 RESTful 服务。 POST 操作可以正常工作,但对同一 URL 的 PUT 操作则不然。它返回如下错误,
Detailed Error Information
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002
url 如下“http://localhost/MyService/Resource.Something.manifest”
相同的设置在 Visual Studio 开发 IIS 中工作正常。
解决方案
基本上默认的ExtensionlessUrlHandler不接受PUT和DELETE动词。只需添加它们即可。
<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" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
为了让 IIS 7.5 接受 PHP 5.4 快速 CGI 驱动的 REST API 的 PUT 和 DELETE,我必须禁用 WebDAV 模块。否则,WebDAV 模块将使用 PUT 或 DELETE 来干预 HTTP 请求。然而,要完成这项工作有点令人困惑,我可能错过了一些步骤或以其他顺序完成。
这些行作为应用程序根目录中 web.config 中
元素的子元素放置。希望这可以减少一些挫败感。似乎服务器的默认设置是接受任何未列出的 HTTP 谓词 - 请参阅
请求过滤 -> 下的设置HTTP 动词 ->编辑功能设置
。人们可以考虑明确添加允许的动词。允许的动词可以在附加此片段后指定,也可以作为
的子级。在客户端计算机上,可以从此处卸载 WebDAV 模块:
使其正常工作的最后一种方法是编辑
C:\Windows\System32\inetsrv\configapplicationhost.config
代码>.在 内->
您将看到一个只有verb="GET,HEAD,POST
的 php 条目 - 修改它以添加您需要的动词,例如: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.
These lines are placed as children of the
<system.webServer>
-element in web.config in the application root.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>
.On a client machine one can uninstall the WebDAV module from here:
The last measure to get it working was by editing
applicationhost.config
found inC:\Windows\System32\inetsrv\config
. Within<system.webServer> -> <handlers>
you will see a php entry that has justverb="GET,HEAD,POST
- amend it to add the verbs you require, e.g.:1.进入IIS管理器。
2.单击您的应用程序。
3.转到“处理程序映射”。
4.在功能列表中,双击“WebDAV”。
5.点击“请求限制”。
6.在“动词”选项卡中选择“所有动词”。
7. 按确定。
1.Go to IIS Manager.
2.Click on your app.
3.Go to "Handler Mappings".
4.In the feature list, double click on "WebDAV".
5.Click on "Request Restrictions".
6.In the tab "Verbs" select "All verbs" .
7.Press OK.
请参阅http://learn.iis.net/page.aspx/901 /iis-express-faq/ 是从 OR wiki 链接的。
从链接(为了便于阅读,未使用块引用):
答:您可以修改
%userprofile%\documents\IISExpress\config
文件夹中的 IIS ExpressapplicationHost.config
。例如,要为无扩展 URL 启用 PUT 和 DELETE,请向下滚动到 IIS ExpressapplicationHost.config
文件的底部,并查找以以下内容开头的处理程序条目: …
在
verb
属性中添加PUT
和DELETE
,以便verb
属性看起来像:verb="GET、HEAD、POST、DEBUG、PUT、DELETE"
。See http://learn.iis.net/page.aspx/901/iis-express-faq/ that is linked from the OR wiki.
From the link (not block-quoted for readability):
A: You can modify the IIS Express
applicationHost.config
in the%userprofile%\documents\IISExpress\config
folder. For example to enable PUT and DELETE for extensionless Urls scroll down to the bottom of the IIS ExpressapplicationHost.config
file and look for a handler entry that starts with:<add name="ExtensionlessUrl-Integrated-4.0"
…In the
verb
attribute addPUT
andDELETE
so theverb
attribute looks like:verb="GET,HEAD,POST,DEBUG,PUT,DELETE"
.我的场景是 IIS 7.5 上网站中的 Web 应用程序。该网站必须继续启用 WebDAV,但 Web 应用程序需要将其关闭才能在其 REST API 中支持 PUT 和 DELETE。
为了使其正常工作,Web 应用程序的 Web.config 需要这样:
与此处其他答案的重要区别是需要 runManagedModulesForWebDavRequests="true"
My scenario was a web application in a web site on IIS 7.5. The web site had to continue to enable WebDAV, but the web application needed to turn it off in order to support PUT and DELETE in its REST API.
To get that working, the web application's Web.config needed this:
The important difference from the other answers here is the need for runManagedModulesForWebDavRequests="true"
对我来说,这在 web.config 中起到了作用。
我使用了以下配置:
希望它有所帮助。 ;-)
For me this does the trick in the web.config.
I used following configuration:
Hope it helps. ;-)
URLScan 工具用户
如果其他答案仍然不起作用并且您收到 404 错误:如果您安装了 URLScan 工具,这些动词可能会被明确拒绝。
您可以配置
URLScan.ini
文件的[AllowVerbs]
和[DenyVerbs]
部分来满足您的需求。谨防安全风险< /a> 启用这些动词。
URLScan tool users
If other answers still don't work and you get 404 error: these verbs may be explicitly rejected by the URLScan tool, if you have it installed.
You can configure
[AllowVerbs]
and[DenyVerbs]
sections of theURLScan.ini
file to meet your needs.Beware of the security risks of enabling these verbs.
对我有用的是完全卸载 WebDav。
What worked for me was uninstalling WebDav completely.
尽管
PUT
和DELETE
已经被列为已处理动词,但进入处理程序映射并设置 WebDAV 来处理所有动词是唯一对我有用的事情。我的工作 web.config 是:Going into the handler mappings and setting WebDAV to handle all verbs is the only thing that worked for me, despite the fact that
PUT
andDELETE
were already listed as handled verbs. The working web.config I have is:在 web.config 中,
您还可以使用 IIS 管理 UI 并全局定义它,或默认 Web 服务器
in the web.config
you can also use the IIS management UI and define this globally, or default web server
我在 IIS 8 中尝试过。
**卸载 WebDav Publishing
卸载步骤
->控制面板->转到程序和功能 ->开窗
功能打开或关闭->选择互联网信息服务->World Wide
Web 服务 -> 常见 HTTP 功能 -> 通过取消选中 WebDAV 选项“删除”WebDAV 发布**
I tried in IIS 8.
**uninstall WebDav Publishing
Steps to uninstall
-> Control Panel -> Go to Programs and features -> Turn windows
featues on or off-> Select Internet Information Services->World Wide
Web Services->Common HTTP Featues->"Remove" WebDAV Publishing by unchecking WebDAV option**
500错误的原因!
大家好,
我也想发布我自己的研究成果,希望对未来的爱好者有所帮助。
正如答案中所建议的,我无法卸载 WebDav,因此我在 Web 配置中添加了以下行(来自其他答案),
但当我启用调试模式时,我收到了 500 错误,发现了这个
答案
由于处理程序映射部分中已存在 ExtensionlessUrlHandler,因此请执行以下操作来解决该问题。
方法 1
1) 转到 IIS 管理器并选择您的应用程序
2) 转到处理程序映射功能
3) 找到 ExtensionlessUrlHandler-Integrated-4.0 并将其删除。
4)在您的webconfig中添加ExtensionlessUrlHandler(如上面的答案所述)
方法 2
1) 从您的 Web 配置中删除 ExtensionlessUrl 处理程序
2) 在 IIS 服务器中单击您的应用程序,转到 HandlerMappings
3) 找到 ExtensionlessUrlHandler-Integrated-4.0(仅此名称,忽略其他名称)
4) 右键单击它并选择编辑
编辑处理程序
5) 单击在“请求限制”上并选择“动词”选项卡和“请求限制”选择所有动词,
这将使无扩展处理程序允许所有动词。
我将使用方法 1,因为我们可以在 web.config 中进行控制。但请确保你
检查部署服务器是否有重复的处理程序定义。
Reason for 500 error !
Hi all,
I want to post my own research too, I hope it would help future enthusiasts.
As suggested in answers, I can't uninstall WebDav so I have added the line below in web config (from other answers)
but I got a 500 error, when I have enabled debug mode found this
Answer
Its because there was already an ExtensionlessUrlHandler in the handler mappings section, do the following to resolve the issue.
Method 1
1) Go to Your IIS Manager and select your app
2) Go to Handler Mappings feature
3) Find ExtensionlessUrlHandler-Integrated-4.0 and delete it.
4) Add ExtensionlessUrlHandler in your webconfig (as mentioned in above answers)
Method 2
1) Remove ExtensionlessUrl handler from your web config
2) Click on your app in IIS Server, go to HandlerMappings
3) Find ExtensionlessUrlHandler-Integrated-4.0 (only this name, ignore others)
4) right click on it and choose Edit
edit handler
5) click on 'Request Restrictions' and select Verbs tab & choose All Verbs
this will enable extensionsless handler to allow all verbs.
I will go with method 1, as we can have control in web.config. But make sure you
check the deployment server for duplicate handler definitions.
我的 web.config 与 asp.net core 1.0
My web.config with asp.net core 1.0
在Windows Server 2012中。
使用管理员权限在记事本中打开 applicationHost.config 文件
applicationHost.config 文件位于 C:\Windows\System32\inetsrv\config 中
找到注意
DELETE 和 PUT HTTP 动词设置为 false。
将它们更改为 true。
现在应如下所示
保存文件。您已在 Web 服务器上启用 HttpPut 和 HttpDelete 请求
In windows server 2012.
Open applicationHost.config file in notepad with Administrator rights
applicationHost.config file is found in C:\Windows\System32\inetsrv\config
Locate the section
Notice DELETE and PUT HTTP Verbs are set to false.
Change them to true.
It should now read as below
Save the file. You have enabled HttpPut and HttpDelete requests on your web server
主要解决方案是从特定网站模块的部分中删除 webdavmodule 。
因此,您可以从 IIS 和 webconfig 中执行此操作。
The main solution is to remove webdavmodule from the specific website'd module's section.
So you can do it from both IIS and in webconfig.
我正在处理同样的问题。我的解决方案是在 Plesk Panel 中关闭 Web 应用程序的防火墙模式。
I was dealing with the same problem. The solution for me was to turn off the Firewall mode of the Web Application in Plesk Panel.