I have a simple ASP.Net WebAPI service that assigns a static variable on POST/PUT and returns the value on GET:
private static State Repo = null;
public State Get()
{
return Repo;
}
public void Post(State value)
{
Repo = value;
}
public void Put(State value)
{
Repo = value;
}
And I have an angular-resource defined like so:
var stateService = angular.module('StateService', ['ngResource']);
stateService.factory('State', function ($resource) {
return $resource('http://localhost:8080/API/State');
});
When I try to do this:
State.get(function (state) {
$scope.data = state.data !== undefined ? state.data : '[Not Set]';
state.data = "newvalue";
state.$save();
});
The get()
works fine, but the $save()
throws this error in chrome:
XMLHttpRequest cannot load http://localhost:8080/API/State. Invalid HTTP status code 405
The webAPI already has CORS enabled (returns Access-Control-Allow-Origin: *
). What am I missing?