iT邦幫忙

0

【已解決】IIS 使用PUT、DELETE、PATCH回傳405 Method Not Allowed

DEV 2020-12-31 14:25:138206 瀏覽

如標題,
後端使用.NET Core MVC做Web API,
前端使用Vue js做SPA,
[HttpPut][HttpDelete][HttpPatch]該掛的屬性都有掛,
使用VS2019的IIS模擬器不會有這個問題,
但發佈到IIS上使用AXIOS PUTDELETEPATCH都會回傳405,
已經試過下列網路上的方法皆無效。

  1. web.config移除WebDAV
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="WebDAVModule" />
    </modules>
    <handlers>
       <remove name="WebDAV" />
        <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
        <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
        <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    
    參考https://blog.johnwu.cc/article/iis-http-405-error.html
  2. applicationhost.config
    handlers加上PUT、DELETE、PATCH
  3. Windows功能,直接關閉WebDAV
    Internet Information Services -> World Wide Web -> 一般HTTP功能 -> WebDAV發行

已經卡關幾個小時了,請問是否有大大遇過類似問題,並成功解決的? 或是知道如何解決的?

https://ithelp.ithome.com.tw/upload/images/20201231/20133978DJBji65mwZ.png

===========================已解決===========================
之前由於不明原因,應用程式集區-整合式會出現伺服器應用程式無法使用,於是無知的我自動改成傳統式,結果問題就出在這裡。

重灌IIS後已一並解決。

看更多先前的討論...收起先前的討論...
Homura iT邦高手 1 級 ‧ 2020-12-31 14:43:50 檢舉
你的錯誤是寫路徑錯誤
不是你說的HTTP request methods的錯誤耶...
DEV iT邦新手 5 級 ‧ 2020-12-31 15:00:50 檢舉
F12 回傳StatusCode是405 Method Not Allowed,
附圖的禁止使用路徑'DELETE'是F12 Preview的結果。
Homura iT邦高手 1 級 ‧ 2020-12-31 15:08:14 檢舉
https://stackoverflow.com/questions/51379356/axios-post-request-not-working
這篇說改用https
不要用http
你試試看?
DEV iT邦新手 5 級 ‧ 2020-12-31 15:14:00 檢舉
一直都是使用https,因為有使用相機的需求。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
allenlwh
iT邦高手 1 級 ‧ 2020-12-31 14:53:35

我的web.config 裡面有一段,請參考看看

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    
  <handlers>    
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />      
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler"  preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>
</system.webServer>
DEV iT邦新手 5 級 ‧ 2020-12-31 15:01:52 檢舉

感謝回覆,這個已經試過無效了。

allenlwh iT邦高手 1 級 ‧ 2020-12-31 16:30:52 檢舉

換個方向,改其他測試工具試試
Postman - 測試 API 神器 > https://ithelp.ithome.com.tw/articles/10201503

DEV iT邦新手 5 級 ‧ 2021-01-04 08:53:17 檢舉

Postman也是得到附圖的結果。
使用DELETE,亂打路徑也是一樣的結果,估計是被IIS擋住了。

我要發表回答

立即登入回答