加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – ashx处理程序DELETE请求不工作HTTP 405.0

发布时间:2020-12-16 07:32:17 所属栏目:asp.Net 来源:网络整理
导读:尝试从我试图实现的 jquery文件上传器向.ashx处理程序发出DELETE请求时,我收到HTTP错误405.0 – 方法不允许错误. 引用这个问题(https://stackoverflow.com/questions/6695587/enabling-put-on-iis-7-5-for-an-ashx-handler-using-windows-authentication)我
尝试从我试图实现的 jquery文件上传器向.ashx处理程序发出DELETE请求时,我收到HTTP错误405.0 – 方法不允许错误.

引用这个问题(https://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,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,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这样的图像或文档?

解决方法

这是最后的web.config部分.我需要添加的东西是缺少的是将staticFileHandler从使用“所有动词”更改为拼写出来的所有动词.

<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    <handlers accessPolicy="Read,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,runtimeVersionv4.0" />
        <add name="SimpleHandlerFactory-ISAPI-2.0" path="*.ashx" verb="GET,DELETE" modules="IsapiModule" scriptProcessor="%windir%Microsoft.NETFrameworkv2.0.50727aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" />
        <add name="StaticFile" path="*" verb="GET,DELETE" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    </handlers>
    <security>
        <authorization>
            <remove users="*" roles="" verbs="" />
            <add accessType="Allow" users="*" verbs="GET,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,FastCGI" verbosity="Verbose" />
                </traceAreas>
                <failureDefinitions statusCodes="405" />
            </add>
        </traceFailedRequests>
    </tracing>        
</system.webServer>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读