2012-08-02 131 views
4

我試圖從jquery文件上載程序向我嘗試實現的.ashx處理程序發出DELETE請求時發生HTTP錯誤405.0-方法不允許錯誤。ashx處理程序刪除請求不起作用HTTP 405.0

引用此問題(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> 

我已經啓用失敗請求跟蹤和它試圖同時基於.ashx的的請求延長我會使用staticFileModule認爲它會嘗試使用SimpleHandlerFactory。

這裏是我打的鏈接:http://local.testsite.com:80/webservices/FileTransferHandler.ashx?f=df69bf1-2a15-43e3-9310-3ca163e2aeb2

爲什麼這個鏈接是使用staticFileModule,是不是對圖像或文件如.jpg和.pdf?

+1

我不是專家,但我想知道是否重要的​​是你的處理程序部分不提及'DELETE' ... – Chris 2012-08-02 13:01:56

+0

這是一個很好的接觸,但可悲的是沒有修復的東西。我編輯了原始問題以反映我的web.config更改。 – 2012-08-02 13:55:18

回答

11

下面是最終的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.Form Section DropDown選擇System.WebServer。 4.選擇處理程序,它會顯示可用的處理程序單擊旁邊的
計數打開處理程序。 5.將PHP_viaFastCGI和添加刪除作爲POST旁邊的動詞。