2014-02-20 88 views
0

我有一個應用程序,我在其中使用OData和Knockout Js。在我的應用程序中,我使用POST,GET和DELETE HTTP Verb,當我託管我的應用程序時,GET和POST不會引發任何錯誤,但DELETE確實會拋出一個錯誤,不知道如何解決它。無法解決網絡錯誤:405方法不允許

下面就是我使用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 

如何解決呢

+0

這是否方法具有[授權]屬性? –

+0

是的,控制器方法的[授權]屬性的整個頁面不僅爲這個DELETE,他們工作正常 – DoIt

+0

可能是一個CORS的問題......這是SO文章的幫助嗎? http://stackoverflow.com/questions/19675835/networkerror-405-method-not-allowed-on-google-contact-delete –

回答

2

即使添加了以下行我的web.config幫我

<system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="WebDAVModule"/> 
    </modules> 
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發佈,然後單擊確定。