无法解决网络错误:405方法不允许

时间:2014-02-20 17:25:01

标签: knockout.js odata httpverbs

我有一个应用程序,我正在使用OData和Knockout Js。在我的应用程序中,我使用POST,GET和DELETE HTTP Verb,当我托管我的应用程序时,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

我该如何解决?

2 个答案:

答案 0 :(得分: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信息服务,然后是万维网服务,然后是通用HTTP功能 3)取消选择 WebDAV发布,然后单击“确定”。

答案 1 :(得分:2)

甚至将以下行添加到我的web.config帮助我

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule"/>
    </modules>