After writing a code using TypeScript and AngularJS, I encountered an issue while using the http.put method to send data to my web API. Instead of receiving the expected response from the Web API and populating the grid, I received a 405 Method Not Allowed error.
Attempts to resolve this problem by adjusting settings in IIS led to another issue - an HTTP Error 500.19 - Internal Server Error when trying to load the application after making changes. Even modifying the web config did not solve the initial problem.
The TypeScript + AngularJS Controller snippet is as follows:
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);
}
This is the relevant snippet of the Web API:
[AllowAnonymous]
[HttpPut]
public HttpResponseMessage PutDoSearch(searchItem value)
{
//...Definitions
}