HTTP错误405方法不允许使用web.API错误

时间:2014-10-16 17:05:53

标签: asp.net iis asp.net-web-api dotnetnuke dotnetnuke-7

我知道我不是第一个遇到这种情况的人,但我已经尝试了所有建议的修复程序,仍然无法让它工作。我想在我的web.API服务和DNN 7中使用DELETE和PUT动词。

以下是我的服务代码:

    routeManager.MapHttpRoute(moduleName, "deleteproduct", "{controller}/{action}/{ID}", New String() {"Krisis.Modules.KrisisStore.Services.Controllers"})

    ' DELETE: /deleteproduct/
    <HttpDelete> _
    <ActionName("deleteproduct")> _
    <ValidateAntiForgeryToken> _
    Public Function DeleteProduct_ById_Full(ID As Integer) As HttpResponseMessage
        Try
            ...
        End Try

    End Function

这是我的ajax调用(使用knockout.js作为我的viewmodel):

// ****** CONFIRM DELETE FUNCTION ************************************************** 
this.confirmDelete = function () {

    //delete product web.Api url
    var sURL = "http://" + window.location.hostname + "/DesktopModules/KrisisStore/api/ProductService/deleteproduct/" + self.selectedProduct().ProductId;

    jQuery.ajax({
        type: "DELETE",
        url: sURL,
        success: function (response) {

            alert('Product Removed');

        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("status: " + xhr.status + "\n" + thrownError);
            //alert('There was an error');
        }
    });

    $('#DeleteModal').foundation('reveal', 'close');
};

我收到以下错误:

HTTP Error 405.0 - Method Not Allowed

The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.

我做了什么:

我找到This SO question并按照接受的答案: 我将动词添加到DNN web.config文件和IIS aplicationhost.config文件中,如下所示:

<add name="ExtensionlessUrl-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ExtensionlessUrl-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" 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" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrl-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0" />

其中一个解决方案是确保禁用webDAV,但我注意到dnn web.config文件已在web.config文件中注释掉这些webDAV行。所以我还注释掉了applicationhost.config文件中的行。

我将从IIS中删除webDAV以查看是否有帮助并更新我的问题。

问题

我仍然收到此错误。有人可以帮我弄清楚如何在IIS 8 express上为DNN 7站点的HTTP请求添加自定义动词。

1 个答案:

答案 0 :(得分:0)

好的,发布太快了。我打开了Windows程序和功能,然后扩展了IIS并取消选中了webDAV。它从IIS中删除它然后一切正常。

如果其他人发现这一点,请注意注释掉IIS中的行不起作用,我不得不从IIS中取消webDAV。

enter image description here