angularjs - IIS 7.5 中不允许使用 Type Script + Angular Js + Web API Status 405 的方法

标签 angularjs http typescript iis-7.5 typescript1.4

我已经使用 Type Script 和 Angular Js 实现了一个代码,并使用了 http.put 并将一些数据传递到我的 Web API,而不是从我的 Web API 获取响应并将其填充到网格中。

但现在的问题是我收到 405 Method Not Allowed 错误 我尝试通过允许所有动词在 IIS 中进行一些更改,但如果我进行了更改并按确定,它将不会加载我的应用程序并给出 HTTP 错误 500.19 - 内部服务器错误。

我也尝试更改我的网络配置,但仍然是同样的问题。 我已经向您展示了我的 TypeScript + Angular Js Controller :-

var customerapp = angular.module('CustomerSearch');
module CustomerSearch.controllers
{
    export class CustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];
        debugger;
        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.search = this.search;
            console.log(angular.element($scope).scope());
        }
        public search = (search: any) => {
            debugger;
           var Search = {
                ActId: search.txtAct,
                checkActiveOnly: search.checkActiveOnly,
                checkParentsOnly: search.checkParentsOnly,
                listCustomerType: search.listCustomerType
            };

            this.$scope.customer = [];
            this.$scope.ticket = [];
            this.$scope.services = [];


            this.$http.put('/API/Search/Search', Search).
                success((data, status, headers, config) => {
                debugger;
                this.$scope.cust_File = data[0].customers;
                this.$scope.ticket_file = data[0].tickets;
                this.$scope.service_file = data[0].services;
            }).
                error((data, status) => {
                debugger;
                console.log("Request Failed");
                alert(status);
                });

        }
    }
    var customerapp = angular.module("CustomerSearch", []);
    customerapp.controller('CustomerCtrl', CustomerSearch.controllers.CustomerCtrl);
}

这是我的 Web API:-

   [AllowAnonymous]
    [HttpPut]
    public HttpResponseMessage PutDoSearch(searchItem value)
    {
      //...Definations
    }

It's the error which i got after making chnages in my web.config and control pa

最佳答案

很可能 WebDAV 已启用并且正在干扰您的请求。如果您不使用它,则需要将其移开,以便您可以对 Web API 使用 PUT 请求。

您应该能够使用您的 web.config 文件执行此操作:

<system.webServer>
    /* ... */
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    <handlers>
        <remove name="WebDAV" />
    </handlers>
    <security>
        <requestFiltering>
            <verbs allowUnlisted="false">
                <add verb="GET" allowed="true" />
                <add verb="POST" allowed="true" />
                <add verb="DELETE" allowed="true" />
                <add verb="PUT" allowed="true" />
            </verbs>
        </requestFiltering>
    </security>
<system.webServer>

您也可以(可选)决定放弃 WebDav 功能,您可以通过导航到:

  1. 控制面板
  2. 卸载程序
  3. 打开或关闭 Windows 功能
  4. 信息系统
  5. 万维网服务
  6. 常见的 HTTP 特性
  7. WebDAV 发布

关于angularjs - IIS 7.5 中不允许使用 Type Script + Angular Js + Web API Status 405 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30601132/

相关文章:

javascript - AngularJs 或 JavaScript 等待某些条件

javascript - 未提供过滤器时 Angular 显示全部

http - SAML 从哪里获得额外的 PF 值

从 ES5 与 ES6 编写的库中导入 TypeScript

javascript - 使用 ui 模式时,ui 路由器范围内的 Angular Controller 不会改变

用于更新 Controller 范围的 Angularjs 服务回调

c - 使用 winHttpApi 或套接字发送大文件是否明智?

java - Red5:如何处理HTTP?

javascript - 如何将TypeScript的导出默认编译为exports = xxx

javascript - 如何使用 Angular Material 在具有可扩展行的表中创建嵌套垫表