ASP.NET Web API - PUT &不允许删除动词 - IIS 8 [英] ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8

查看:20
本文介绍了ASP.NET Web API - PUT &不允许删除动词 - IIS 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从 Visual Studio 2010 升级到了 Visual Studio 2012 RC.安装程序还会安装 IIS 8 Express,Visual Studio 现在将其用作默认 Web 服务器.

I recently upgraded from Visual Studio 2010 to the Visual Studio 2012 RC. The installer also installs IIS 8 Express which Visual Studio now uses as the default web server.

IIS 8 阻止了我使用 PUT 和 DELETE 动词的 WEB API 请求.IIS 返回 405 错误,请求的资源不支持 http 方法 'PUT'.

IIS 8 is blocking my WEB API requests that use PUT AND DELETE verbs. IIS returns a 405 error, The requested resource does not support http method 'PUT'.

我知道过去人们对此有疑问,并且 Stack Overflow 上有几条关于它的消息.使用 IIS 7 Express 的解决方案是卸载 WebDav.不幸的是,我在 IIS 8 中看不到任何方法可以做到这一点.

I know people have issues with this in the past and there are several messages about it on Stack Overflow. With IIS 7 Express the solution was to uninstall WebDav. Unfortunately I don't see any way to do that with IIS 8.

我已经尝试从 applicationhost.config 中编辑出 WebDav 部分,但这并没有帮助.例如,我从配置文件中删除了 <add name="WebDAVModule" image="%IIS_BIN%webdav.dll"/>.

I've tried editing out the WebDav sections from applicationhost.config but that hasn't helped. For example I removed <add name="WebDAVModule" image="%IIS_BIN%webdav.dll" /> from the config file.

我在这上面花了太长时间.必须有一个简单的方法来启用 PUT 和 DELETE?

I've spent far too long on this. There must be a simple way to enable PUT and DELETE?

推荐答案

好的.我终于明白了这一点.您需要跳过一些障碍才能使 PUT 和 DELETE 动词与 IIS8 一起正常工作.事实上,如果您安装 VS 2012 的候选版本并创建一个新的 WEB API 项目,您会发现示例 PUT 和 DELETE 方法会立即返回 404 错误.

Okay. I finally got to the bottom of this. You need to jump through some hoops to get the PUT and DELETE verbs working correctly with IIS8. In fact if you install the release candidate of VS 2012 and create a new WEB API project you'll find that the sample PUT and DELETE methods return 404 errors out of the box.

要在 Web API 中使用 PUT 和 DELETE 动词,您需要编辑 %userprofile%documentsiisexpressconfigapplicationhost.config 并将动词添加到 ExtensionlessUrl 处理程序,如下所示:

To use the PUT and DELETE verbs with the Web API you need to edit %userprofile%documentsiisexpressconfigapplicationhost.config and add the verbs to the ExtensionlessUrl handler as follows:

改变这一行:

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

到:

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

除上述之外,您还应确保 WebDAV 不会干扰您的请求.这可以通过注释掉 applicationhost.config 中的以下几行来完成.

In addition to the above you should ensure WebDAV is not interfering with your requests. This can be done by commenting out the following lines from applicationhost.config.

<add name="WebDAVModule" image="%IIS_BIN%webdav.dll" />
<add name="WebDAVModule" /> 
<add name="WebDAV" path="*" verb="PROPFIND,PROPPATCH,MKCOL,PUT,COPY,DELETE,MOVE,LOCK,UNLOCK" modules="WebDAVModule" resourceType="Unspecified" requireAccess="None" />

另请注意,默认的 Web API 约定是您的方法名称应与调用的 HTTP 动词相同.例如,如果您发送 HTTP 删除请求,您的方法默认应命名为 Delete.

Also be aware that the default Web API convention is that your method name should be the same as the invoked HTTP verb. For example if you're sending an HTTP delete request your method, by default, should be named Delete.

这篇关于ASP.NET Web API - PUT &amp;不允许删除动词 - IIS 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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