Search code examples
angularjshttptypescriptiis-7.5typescript1.4

Method Put not Allowed in IIS 7.5 using Type Script + Angular Js + Web API Status 405


I have implemented a code using Type Script and Angular Js and used http.put and passing some data to my web API than get the response from my Web API and fill it into the grid.

But now the problem is i am getting error of 405 Method Not Allowed I tried to make some changes in IIS as by allowing all verbs but if i made the changes and press ok it will not load my application and give HTTP Error 500.19 - Internal Server Error.

I have tried to make changes in my web config as well but still same problem. I have shown you my 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);
}

Here is my 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


Solution

  • It is likely that WebDAV is enabled and is interfering with your request. If you aren't using it, you need to get it out of the way so you can use PUT requests for your Web API.

    You should be able to do this using your web.config file:

    <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>
    

    You may also (optionally) decide to ditch the WebDav feature, which you can do by navigating to:

    1. Control Panel
    2. Uninstall Program
    3. Turn Windows features on or off
    4. IIS
    5. World Wide Web Services
    6. Common HTTP feautre
    7. WebDAV Publishing