【问题标题】:http error 405 method not allowed error with web.APIhttp 错误 405 方法不允许 web.API 错误
【发布时间】:2014-12-12 03:40:17
【问题描述】:

我知道我不是第一个遇到此问题的人,但我已经尝试了所有建议的修复程序,但仍然无法使其正常工作。我想在我的 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 作为我的视图模型):

// ****** 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 请求添加自定义动词。

【问题讨论】:

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


    【解决方案1】:

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

    如果其他人发现此问题,请注意注释掉 IIS 中的行不起作用,我必须从 IIS 中卸载 webDAV。

    【讨论】:

      猜你喜欢
      • 2011-06-21
      • 2017-10-16
      • 1970-01-01
      • 2020-02-13
      • 2016-08-24
      • 2018-01-07
      • 2018-06-05
      • 2017-11-13
      • 2018-07-06
      相关资源
      最近更新 更多