ashx处理程序的DELETE请求无法正常工作,HTTP 405.0错误。

4
我在尝试使用jquery文件上传程序实现向.ashx处理程序发起DELETE请求时出现了HTTP错误405.0-不允许的方法错误。
参考这个问题(https://dev59.com/9VnUa4cB1Zd3GeqPYj1U),我已经在web.config文件中添加了下面的部分,但似乎无法消除错误。是否还有其他技巧可以使DELETE方法正常工作?
我正在使用.Net 4.0和IIS7.5,并且同时运行windows azure存储模拟器。
<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    <handlers accessPolicy="Read, Write, Execute, Script">
        <remove name="WebDAV" />
        <remove name="SimpleHandlerFactory-Integrated-4.0" />
        <remove name="SimpleHandlerFactory-Integrated" />
        <add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode" />
        <add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <security>
        <authorization>
            <remove users="*" roles="" verbs="" />
            <add accessType="Allow" users="*" verbs="GET,HEAD,POST,PUT,DELETE,DEBUG" />
        </authorization>
    </security>
</system.webServer>

以下是前端代码调用处理程序的代码:

<td class="delete">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" data-url="/webservices/FileTransferHandler.ashx?f=df69bfd1-2a15-43e3-9310-3ca163e2aeb2" data-type="DELETE" role="button" aria-disabled="false" title="Delete">
<span class="ui-button-icon-primary ui-icon ui-icon-trash"></span>
<span class="ui-button-text">Delete</span>
</button>
</td>

我已启用失败请求跟踪,但它正在尝试使用staticFileModule,而根据请求扩展名.ashx,我认为它应该尝试使用SimpleHandlerFactory。 这是我访问的链接:http://local.testsite.com:80/webservices/FileTransferHandler.ashx?f=df69bf1-2a15-43e3-9310-3ca163e2aeb2 为什么这个链接会使用staticFileModule呢?难道不是针对像.jpg和.pdf这样的图像或文档吗?

1
我不是专家,但我想知道你的处理程序部分没有提到“DELETE”是否重要... - Chris
那是一个很好的发现,但遗憾的是并没有解决问题。我已经编辑了原始问题以反映我的web.config更改。 - Andrew Walters
2个回答

13

以下是最终的web.config部分。我需要添加的内容是更改静态文件处理程序(staticFileHandler)从使用"所有动词"到拼写出来的所有动词。

<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    <handlers accessPolicy="Read, Write, Execute, Script">
        <remove name="StaticFile" />
        <remove name="SimpleHandlerFactory-ISAPI-2.0" />
        <remove name="WebDAV" />
        <remove name="SimpleHandlerFactory-Integrated-4.0" />
        <remove name="SimpleHandlerFactory-Integrated" />
        <add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode" />
        <add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode,runtimeVersionv4.0" />
        <add name="SimpleHandlerFactory-ISAPI-2.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" 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="StaticFile" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    </handlers>
    <security>
        <authorization>
            <remove users="*" roles="" verbs="" />
            <add accessType="Allow" users="*" verbs="GET,HEAD,POST,PUT,DELETE,DEBUG" />
        </authorization>
    </security>
    <tracing>
        <traceFailedRequests>
            <remove path="*" />
            <add path="*">
                <traceAreas>
                    <add provider="ASP" verbosity="Verbose" />
                    <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                    <add provider="ISAPI Extension" verbosity="Verbose" />
                    <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
                </traceAreas>
                <failureDefinitions statusCodes="405" />
            </add>
        </traceFailedRequests>
    </tracing>        
</system.webServer>

0
如果您正在IIS服务器中使用PHP,则请按照以下步骤操作。 我通过为PHP模块添加删除动词来解决了问题。 1.打开IIS。 2.转到配置编辑器。 3.从部分下拉菜单中选择System.WebServer。 4.选择处理程序,它将显示可用的处理程序,单击next to count以打开处理程序。 5.转到PHP_viaFastCGI并在POST旁边添加Delete作为动词。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接