rest - IIS7.5 尝试使用 DELETE 动词时出现 500 内部服务器错误

标签 rest iis iis-7.5 http-delete

我正在尝试发出 DELETE到 IIS7.5 资源:

DELETE http://198.252.206.16:48251/Test/foo.ashx HTTP/1.1
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Host: 198.252.206.16:48251
Content-Length: 0
Connection: Keep-Alive
Pragma: no-cache

服务器响应:
HTTP/1.1 500 Internal Server Error
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 12 Feb 2014 01:01:30 GMT
Content-Length: 0

最可恶的是:
  • 它在 Cassini(Visual Studio 使用的基于 .NET 的 Web 服务器)中运行良好
  • Windows 事件日志中未记录任何内容
  • 网站的 web.config 中的自定义错误已关闭
  • 未过滤任何动词(或包含所有动词)
  • WebDAV 模块被禁用
  • 未安装 LiveStreamingHandler 模块

  • 为什么 IIS 不起作用?

    重现步骤

    使用通用处理程序创建一个网站:

    Foo.ashx
    <%@ WebHandler Language="C#" Class="Foo" %>
    
    using System;
    using System.Web;
    
    public class Foo : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
        }
    
        public bool IsReusable { get { return false; } }
    }
    

    然后发出 DELETE资源的动词。如果您愿意,可以使用 Fiddler 来编写请求:

    enter image description here

    你问的其他动词呢?

    你没有尝试复制它,是吗?好吧,我将在这里向您展示结果:
  • GET : 作品
  • POST : 作品
  • PUT : 作品
  • HEAD : 作品
  • TRACE : 501 Not Implemented
  • DELETE : 500 Internal Server Error
  • SEARCH : 405 Method Not Allowed
  • PROPFIND : 500 Internal Server Error
  • PROPPATCH : 500 Internal Server Error
  • PATCH : 405 Method Not Allowed
  • MKCOL : 405 Method Not Allowed
  • COPY : 500 Internal Server Error
  • MOVE : 500 Internal Server Error
  • LOCK : 500 Internal Server Error
  • UNLOCK : 500 Internal Server Error
  • OPTIONS : 200 OK
  • IISUCKSFOO 405 Method Not Allowed

  • 只是为了保持肛门内存,来自web.config的相关部分的片段:
    <?xml version="1.0"?>
    <configuration>
        <system.web>
            <httpRuntime/>
            <!-- IISFIX: By default IIS hides errors-->
            <customErrors mode="Off"/>
            <!-- IISFIX: By default IIS ignores the browser's culture -->
            <globalization culture="auto" uiCulture="auto"/>
            <!--Doesn't work for ASP.net web-sites, only ASP.net applications-->
            <trace enabled="true" requestLimit="40" localOnly="false" />
    
            <compilation debug="true" targetFramework="4.0">
                <assemblies>
                    <add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                    <add assembly="System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                    <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                </assemblies>
            </compilation>
        </system.web>
    
        <!-- ASP.net web-sites do not support WebPageTraceListener (only ASP.net web-applications) 
      So this section doesn't work; and does nothing. 
      But if Microsoft ever fixes IIS, we will start working automagically. -->
        <system.diagnostics>
            <trace>
                <listeners>
                    <add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
                </listeners>
            </trace>
        </system.diagnostics>
    
        <system.webServer>
            <!-- IISFIX: By default IIS ignores custom error pages -->
            <httpErrors existingResponse="PassThrough"/>
            <defaultDocument>
                <files>
                    <clear/>
                    <add value="Default.htm"/>
                    <add value="Default.asp"/>
                    <add value="index.htm"/>
                    <add value="index.html"/>
                    <add value="iisstart.htm"/>
                    <add value="default.aspx"/>
                    <add value="test.htm"/>
                </files>
            </defaultDocument>
    
            <!--IISFIX: By default IIS doesn't understand HTTP protocol-->
            <security>
                <requestFiltering>
                    <verbs>
                        <add verb="OPTIONS" allowed="true" />
                        <add verb="GET" allowed="true" />
                        <add verb="HEAD" allowed="true" />
                        <add verb="POST" allowed="true" />
                        <add verb="PUT" allowed="true" />
                        <add verb="TRACE" allowed="true" />
                        <add verb="DELETE" allowed="true" />
                    </verbs>
                </requestFiltering>
            </security>
    
            <modules runAllManagedModulesForAllRequests="true">
                <!--IISFIX: Whatever this is, it causes 405 Method Not Allowed errors on IIS when using PUT. (Microsoft's broken by defult)-->
                <remove name="WebDAVModule"/>
            </modules>
    
        </system.webServer>
    </configuration>
    

    编辑 - 忘记动词截图:

    enter image description here

    这个问题在标题中被充分提出。这篇文章的其余部分只是为了让它看起来像是在展示研究成果。这意味着您必须对其进行投票 - 投票箭头上的工具提示是这样说的!

    最佳答案

    我发现在上述解决方案中从处理程序和模块中删除 webDav 引用仍然会导致 IIS 7.5、IIS 7 Windows server 2008 r2(我从未测试过 IIS 8)用于 http 方法 PUT、DELETE

    HTTP 错误 500.21 - 内部服务器错误
    处理程序“ExtensionlessUrlHandler-Integrated-4.0”有一个坏模块“ManagedPipelineHandler”

    此服务器错误具有误导性,也适用于缺少处理程序的不正确 .net 安装,并且可以通过重新安装 .Net 来修复,但这可能不是解决方案,如果它只影响对无扩展名的 PUT 或 DELETE 请求路由处理程序(GET、POST 和 OPTIONS 都很好)。我读了很多关于在 MVC 和 Web api 中启用 put 和 delete 方法的帖子,这些帖子似乎声称这是一个修复,所以我还是尝试了几次,重新启动 IIS 等,错误没有改变。

    在我将 runManagedModulesForWebDavRequests="true"属性添加到 modules 元素之前,问题并没有消失。

    < 模块 runAllManagedModulesForAllRequests="true"runManagedModulesForWebDavRequests="true">

    http://www.iis.net/configreference/system.webserver/modules

    默认情况下 runManagedModulesForWebDavRequests ="false"这意味着任何 webDav 请求都被路由到 WebDav。据我所知,就 IIS 而言,webdav 请求是所有 http PUT 或 DELETE 请求,即使您已从 web 配置中删除了 webdav 处理程序并且您的请求正文不符合 webdav 请求。卸载 webDav 也可能解决问题,但我从未尝试过;我有其他站点在依赖它的同一台服务器上运行。

    关于rest - IIS7.5 尝试使用 DELETE 动词时出现 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21716930/

    相关文章:

    java - 如何使用 @GET 从 RESTful 服务响应 List<>

    asp.net - 是否有与 Tomcat 等效的 IIS?

    Powershell - 应用程序池 - 高级设置 - 定期时间间隔

    iis-7.5 - 事件目录授权 : IIS vs Visual Studio Dev server

    asp.net - 文件上传和结果池杀死了 ASP.NET Web 应用程序

    JAVA - 无效数据的自定义错误响应

    rest - 关闭 requestLog

    java - 自 Java 升级到 8 后,启动 Java 的 Windows 服务无法正常工作

    asp.net - IIS Url Rewrite 的 preCondition 属性上的模式 ="."是什么意思?

    windows - 如何以编程方式在 IIS 中设置身份验证方法