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 G
On Web.config, comment the line <remove name="OPTIONSVerbHandler" />
at
<system.webServer>
<handlers>
If you are using CORS config by web.config file.
For some CORS requests, the browser sends an additional request, called a “preflight request”, before it sends the actual request for the resource.
The pre-flight request uses the HTTP OPTIONS (405 status code) method. It includes two special headers:
Even if you had made it CORS enabled, and it is working for GET
request and you have told it is showing 405 HTTP Status
for POST
request. This is because, POST,PUT,DELETE
request are not safe request, they first send request OPTIONS
request, you have to respond to that will required hedaers such as Access-Control-Allow-Origin: *
, Access-Control-Allow-Methods: POST
, and then it will again send POST
request , and it will work then.
Please verify what are the headers you are sending in response. i.e. To make successful CORS POST
request, atleast you have to send Access-Control-Allow-Methods: POST
along with Access-Control-Allow-Origin: *
.
Steps to make it CORS enabled:
Next, add the [EnableCors] attribute to the Controller class:
With following params
[EnableCors(origins: "your_domain", headers: "*", methods: "POST")]
Redeploy your WebAPI project.
SOURCE - http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
More links - http://www.codeproject.com/Articles/742532/Using-Web-API-Individual-User-Account-plus-CORS-En