【问题标题】:ashx handler DELETE request not working HTTP 405.0ashx 处理程序删除请求不起作用 HTTP 405.0
【发布时间】:2012-08-02 02:45:20
【问题描述】:

我在尝试从我尝试实现的 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 等图像或文档吗?

【问题讨论】:

  • 我不是专家,但我想知道你的处理程序部分没有提到DELETE...
  • 这是一个很好的收获,但遗憾的是没有解决问题。我已经编辑了原始问题以反映我的 web.config 更改。

标签: asp.net iis-7 iis-7.5


【解决方案1】:

这是最后的 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>

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      相关资源
      最近更新 更多