IIS7.5给出尝试使用DELETE动词
我想发出一个DELETE
到IIS7.5资源时500内部服务器错误:IIS7.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
这种该死的事情是:
- 它工作正常,内卡西尼(由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撰写的要求,如果你喜欢:
什么其他动词你问?
你没有尝试重现它,是吗?好吧,我会告诉你结果在这里:
-
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>
编辑 - 忘记动词的截图:
的问题充分提出的称号。这篇文章的其余部分只是填充以使其看起来像表明研究工作;这意味着你必须注册它 - upvote箭头上的工具提示是这么说的!
答案原来是由微软的更多引起的,默认为政策。
而不是作为一个网络服务器,接受请求和处理它们,默认情况下ASP.net决定忽略大多数请求 - 因为它认为用户不应该这样做。
的解决方案是翻录与ASP.net了IIS的所有内容,然后重新正确添加:
的web.config
<?xml version="1.0"?>
<configuration>
<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.config中有文件的硬编码路径。
为什么,哦,为什么微软不能做正确的事情。
为了完整
对于我自己的参考,这里有我需要每一个,因为默认值是错误的时间添加到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>
我发现,去除处理有webDav引用和上述解决方案中的模块仍导致HTTP方法PUT,DELETE
HTTP错误500.21 - 内部服务器错误IIS 7.5 Windows Server 2008 r2(我从未测试过IIS 8)处理程序“ExtensionlessUrlHandler集成4.0”有一个坏的模块“ManagedPipelineHandler”
此服务器错误是误导,也给不正确.net安装丢失处理程序,可以通过重新安装.Net,但这可能不是一个解决方案,如果它只影响PUT或DELETE对无扩展路由处理程序的请求(GET,POST和OPTIONS很好)。我阅读了许多关于在MVC和Web API中启用放入和删除方法的帖子,似乎声称这是一个修复程序,所以无论如何我尝试了几次,重新启动IIS等,没有改变错误。
问题没有消失,直到我将模块元素的runManagedModulesForWebDavRequests =“true”属性添加为止。
<模块runAllManagedModulesForAllRequests = “真” runManagedModulesForWebDavRequests = “真” >
http://www.iis.net/configreference/system.webserver/modules
默认runManagedModulesForWebDavRequests = “假”,这意味着任何WebDAV请求被路由到的WebDav。据我推论,即使你已经从web config中删除了webdav处理程序,并且你的请求主体不符合webdav请求,webdav请求也是所有关于IIS的http PUT或DELETE请求。卸载webDav可能也会纠正问题,但我从未尝试过;我有其他网站在依赖它的同一台服务器上运行。
在将来需要注意的一点是,当你的代码被部署到任何非本地的东西时,你会将可能的硬编码凭证更改为通用访问帐户。我有这个确切的问题整整一天半,看到一个DELETE
。与LDAP
一起使用的净请求正在使用前雇员的硬编码员工ID作为UserPrincipalName
。它工作正常,直到他的ID终于从我们的系统中删除,然后一切都变糟糕。再过一天半之后,我们发现用于测试目的的硬编码证书。简单的例子来说明在不同的测试环境中必须考虑的不同事情。
终于!无论IIS7 +版本如何,都可以使通用处理程序正常工作的解决方案。 –
我能够通过将添加到模块部分并将添加到处理程序部分(都显示在上面)来获得删除工作。 –
只需在处理程序中添加''就足以解决我的问题(我已经删除了WebDAVModule) –