的ASP.NET Web API - PUT和放大器; DELETE动词不允许 - IIS 8 [英] ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8

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

问题描述

我最近从Visual Studio 2010升级到Visual Studio 2012 RC。安装程序还会安装IIS 8防爆preSS它的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方法把'

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'.

我知道人们在过去有问题,这点,有关于它的几个消息对堆栈溢出。在IIS 7防爆preSS的解决办法是卸载的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路段但是这并没有帮助。例如我删除<添加名称=WebDAVModule形象=%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.

要与你需要编辑%USERPROFILE%\\文件的Web API使用PUT和DELETE动词\\ iisex preSS \\设置\\对ApplicationHost.config和动词添加到ExtensionlessUrl处理程序如下:

To use the PUT and DELETE verbs with the Web API you need to edit %userprofile%\documents\iisexpress\config\applicationhost.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请求删除你的方法,默认情况下,应该命名为删除。

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和放大器; DELETE动词不允许 - IIS 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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