I am making an api call to a Delete
method like this -
$http.delete('http://localhost:45467/api/v1/proddetails/' + prodId, null )
.success(function (data, status, headers, config) {
if(data.status == "200")
{
console.log('data deleted');
}
deferred.resolve(data);
})
.error(function (data, status, headers, config) {
console.log("some error occurred");
deferred.reject(data);
});
The delete endpoint looks like this -
[HttpDelete]
public HttpResponseMessage Delete(int productId)
When I run this and look into the Chrome console, I am presented with this error -
OPTIONS http://localhost:45467/api/v1/proddetails/34
(index):1 XMLHttpRequest cannot load
http://localhost:45467/api/v1/proddetails/34. No 'Access-Control-Allow-
Origin' header is present on the requested resource. Origin
'http://localhost:5100' is therefore not allowed access. The response had
HTTP status code 405.
Can't seem to figure out what's wrong here. The other Get and Post requests are working fine. How to fix this?
Note1: I have CORS already enabled -
[EnableCors(origins: "*", headers: "*", methods: "*")]
Note2: I am making use of interceptors
to add an auth token to each request. I am not sure if that is causing any issue.
Note3: This is how I define route in asp.net webapiconfig file -
config.Routes.MapHttpRoute(
name: "ProdApi",
routeTemplate: "api/v1/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Thanks in advance.