0

OData と Knockout Js を使用しているアプリケーションがあります。私のアプリケーションでは、POST、GET、および DELETE HTTP 動詞を使用しています。アプリケーションをホストしたときに、GET と POST はエラーをスローしませんが、DELETE はエラーをスローし、修正方法がわかりません。

以下は、DELETEを使用している場所です

self.remove = function (canadiancrude) {

        var conf = confirm("Are you sure you want to delete this record?");
        if (conf == true) {
            $.ajax({
                url: '/odata/Canadiancrudes(' + canadiancrude.Id + ')',
                type: 'DELETE',
                contentType: 'application/json',
                dataType: 'json'
            });
        }
    }

そして、エラーは

405 - HTTP verb used to access this page is not allowed.
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

"NetworkError: 405 Method Not Allowed

どうすれば修正できますか

4

2 に答える 2

2

以下の行を web.config に追加しても助けになりました

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule"/>
    </modules>
于 2014-02-21T17:12:00.160 に答える
2

リクエストを変更してみてください:

$.ajax({
    url: '/odata/Canadiancrudes(' + canadiancrude.Id + ')',
    type: 'DELETE',
    dataType: 'json',
    headers: { 
        "Content-Type": "application/json",
        "X-HTTP-Method-Override": "DELETE" }
});

また、IIS を使用している場合は、次の手順を実行できます
。1) コントロール パネルで、[プログラムと機能] をクリックし、[Windows の機能の有効化または無効化] をクリックします。
2) Internet Information Services、World Wide Web Services、Common HTTP Features の順に展開します。
3) [WebDAV 公開] の選択を解除し、[OK] をクリックします。

于 2014-02-20T22:48:49.040 に答える