IIS7.5在尝试使用服务器时出现500内部服务器错误

yk9xbfzb  于 2023-11-19  发布在  其他
关注(0)|答案(4)|浏览(156)

我正在尝试向IIS 7.5资源发出DELETE

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模块已禁用
  • 未安装LiveStreamingCloud模块

为什么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来编写请求:
x1c 0d1x的数据

你问的其他动词呢?

你没有试着复制它,是吗?好吧,我会在这里向你展示结果:

GET 工作 *
POST 工作 *
PUT 工作 *
HEAD 工作 *
*TRACE501 Not Implemented
*DELETE500 Internal Server Error
*SEARCH405 Method Not Allowed
*PROPFIND500 Internal Server Error
*PROPPATCH500 Internal Server Error
*PATCH405 Method Not Allowed
*MKCOL405 Method Not Allowed
*COPY500 Internal Server Error
*MOVE500 Internal Server Error
*LOCK500 Internal Server Error
*UNLOCK500 Internal Server Error
*OPTIONS200 OK
*IISUCKSFOO405 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>

编辑-忘记动词截图:



这个问题在标题中已经问得很清楚了。文章的其余部分只是为了让它看起来像是在展示研究成果;这意味着你必须对它投赞成票--赞成票箭头上的工具提示是这么说的!

ecfsfe2w

ecfsfe2w1#

答案原来是由更多的微软的 * 打破默认 * 政策。
ASP.net不是充当Web服务器,接受请求并处理它们,而是默认决定忽略大多数请求-因为它认为用户不应该这样做。
解决方案是将与ASP.net相关的所有内容从IIS中删除,然后正确地重新添加:

web.config

<?xml version="1.0"?>
<configuration>
</system.webServer>
    <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>
    <handlers>
         <!--IISFIX: ASP.net is broken by default. By default they will not accept verbs from the client.
         First we have to rip out everything related to ASP.net-->
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
      <remove name="SimpleHandlerFactory-ISAPI-2.0-64"/>
      <remove name="SimpleHandlerFactory-ISAPI-2.0"/>
      <remove name="SimpleHandlerFactory-Integrated"/>
      <remove name="SimpleHandlerFactory-Integrated-4.0"/>
      <remove name="SimpleHandlerFactory-ISAPI-4.0_64bit"/>
      <remove name="SimpleHandlerFactory-ISAPI-4.0_32bit"/>
         <!-- IISFIX: Now that we're ripped out everything related to ASP.net, put them back correctly.-->
      <add name="SimpleHandlerFactory-ISAPI-4.0_32bit" path="*.ashx" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
      <add name="SimpleHandlerFactory-ISAPI-4.0_64bit" path="*.ashx" verb="*" 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"/>
      <add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0"/>
      <add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode"/>
      <add name="SimpleHandlerFactory-ISAPI-2.0" path="*.ashx" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
      <add name="SimpleHandlerFactory-ISAPI-2.0-64" path="*.ashx" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness64" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="*" 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"/>

      <!--IISFIX: WebDAV is also buggy, and interferes with client requests-->
      <remove name="WebDAV"/>

    </handlers>
  </system.webServer>
</configuration>

字符串
现在的问题是,网站将无法在其他任何人的机器上工作;现在在web.xml中有硬编码的文件路径。
为什么,哦,为什么,微软不能把事情做好。

为了完整

作为我自己的参考,以下是我每次都需要添加到web.config的其他内容,因为默认值是错误的:

<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"/>
  </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"/>
  </system.webServer>

rxztt3cl

rxztt3cl2#

我发现,在上述解决方案中,从处理程序和模块中删除webDav引用仍然会导致IIS 7.5,IIS 7 Windows Server 2008 r2(我从未测试过IIS 8)用于http方法PUT,PUT,
HTTP错误500.21 -内部服务器错误“ExtensionlessUrlHandler-Integrated-4.0”有一个坏模块“ManagedPipelineError”
此服务器错误具有误导性,也适用于处理程序丢失的不正确.net安装,可以通过重新安装.Net来修复,但如果它只影响对无扩展路由处理程序的PUT或NULL请求,则可能不是解决方案(GET、POST、(可选).我读了很多关于在MVC和Web API中启用put和delete方法的帖子,这些帖子似乎声称这是一个修复方法,所以我还是尝试了几次,重新启动IIS等,错误没有改变。
直到我向modules元素添加了runManagedModulesForWebDavRequests=“true”属性,问题才消失。
< modules runAllManagedModulesForAllRequests="true" runManagedModulesForWebDavRequests="true" >
http://www.iis.net/configreference/system.webserver/modules
默认情况下,runManagedModulesForWebDavRequests =“false”,这意味着任何webDav请求都被路由到WebDav。据我所知,就IIS而言,webDav请求都是HTTP PUT或HTTP PUT请求,即使您已经从Web配置中删除了webDav处理程序,并且您的请求主体不符合webDav请求。卸载webDav也可能解决这个问题,但我从未尝试过;我有其他网站运行在同一台服务器上,依赖于它。

0vvn1miw

0vvn1miw3#

我在这里找到了答案:
带IIS的ASP.NET Core-不允许HTTP动词
这是一个web.config

<configuration>
<!-- To customize the asp.net core module uncomment and edit the following section. 
     For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    <handlers>
        <remove name="aspNetCore" />
        <remove name="WebDAV" />
        <!-- I removed the following handlers too, but these
             can probably be ignored for most installations -->
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <remove name="OPTIONSVerbHandler" />
        <remove name="TRACEVerbHandler" />

        <add name="aspNetCore" 
             path="*" 
             verb="*" 
             modules="AspNetCoreModule" 
             resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" 
                arguments="%LAUNCHER_ARGS%" 
                stdoutLogEnabled="false"
                stdoutLogFile=".\logs\stdout" />
</system.webServer>

字符串

eqqqjvef

eqqqjvef4#

将来需要注意的是,当你的代码被部署到任何非本地的东西时,您可以将可能的硬编码凭据更改为通用访问帐户。我有一整天半的时间都遇到了这个问题,并且看到一个与LDAP一起工作的DELETE .net请求使用了一个前雇员的硬编码雇员ID作为UserPrincipalName。它工作得很好,直到他的ID终于从我们的系统中删除了,然后一切都变坏了。一天半后,我们又发现了用于测试目的的硬编码凭据。简单的例子来说明在不同的测试环境中必须考虑的不同事情。

相关问题