4

我在尝试从我尝试实现的 jquery 文件上传器向 .ashx 处理程序发出 DELETE 请求时收到 HTTP 错误 405.0 - Method Not Allowed 错误。

参考这个问题(http://stackoverflow.com/questions/6695587/enabling-put-on-iis-7-5-for-an-ashx-handler-using-windows-authentication)我已将以下部分添加到我的 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 之类的图像或文档吗?

4

2 回答 2

12

这是最后的 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>
于 2012-08-03T01:52:57.597 回答
0

如果您在 IIS 服务器中使用 PHP,请按照以下步骤操作。我通过为 PHP 模块添加删除动词解决了这些问题。1.打开IIS。2.进入配置编辑器。3.Form Section DropDown 选择System.WebServer。4.选择处理程序,它将显示可用的处理程序单击旁边的
计数以打开处理程序。5.转到 PHP_viaFastCGI 并在 POST 旁边添加删除作为动词。

于 2016-07-28T11:28:09.507 回答