我正在尝试向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
: 工作 *
*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>
型
编辑-忘记动词截图:
的
这个问题在标题中已经问得很清楚了。文章的其余部分只是为了让它看起来像是在展示研究成果;这意味着你必须对它投赞成票--赞成票箭头上的工具提示是这么说的!
4条答案
按热度按时间ecfsfe2w1#
答案原来是由更多的微软的 * 打破默认 * 政策。
ASP.net不是充当Web服务器,接受请求并处理它们,而是默认决定忽略大多数请求-因为它认为用户不应该这样做。
解决方案是将与ASP.net相关的所有内容从IIS中删除,然后正确地重新添加:
web.config
字符串
现在的问题是,网站将无法在其他任何人的机器上工作;现在在web.xml中有硬编码的文件路径。
为什么,哦,为什么,微软不能把事情做好。
为了完整
作为我自己的参考,以下是我每次都需要添加到
web.config
的其他内容,因为默认值是错误的:型
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也可能解决这个问题,但我从未尝试过;我有其他网站运行在同一台服务器上,依赖于它。
0vvn1miw3#
我在这里找到了答案:
带IIS的ASP.NET Core-不允许HTTP动词
这是一个web.config
字符串
eqqqjvef4#
将来需要注意的是,当你的代码被部署到任何非本地的东西时,您可以将可能的硬编码凭据更改为通用访问帐户。我有一整天半的时间都遇到了这个问题,并且看到一个与
LDAP
一起工作的DELETE
.net请求使用了一个前雇员的硬编码雇员ID作为UserPrincipalName
。它工作得很好,直到他的ID终于从我们的系统中删除了,然后一切都变坏了。一天半后,我们又发现了用于测试目的的硬编码凭据。简单的例子来说明在不同的测试环境中必须考虑的不同事情。