2

Feel i've spent quite a lot of time trying to get this to work. There's a bunch of helpful SO answers on the topic:

But... none actually solved mine. I feel it's time to phrase my own question, explain what i've done and what I experience is the issue I have.

  1. Installed Microsoft.AspNet.WebApi.Cors via NuGet
  2. Added attribute [EnableCors("http://localhost:PORT", "*", "GET,POST,DELETE,OPTIONS")] on my WebAPI controller.

GET requests works at this point, like a charm.

When I do PUT or DELETE, the pre-flight request fails. I get an internal server error reponse in the client browser. Turns out that the OPTIONS request fails because I have no options method in my web api controller.

By adding the options method as follows:

public HttpResponseMessage Options()
{
    var response = new HttpResponseMessage
    {
        StatusCode = HttpStatusCode.OK
    };
    return response;
}

PUT and DELETE requests does work, hurray!

I'm not sure where to draw the line of the responsibility of the developer vs the framework, but it feels like I should not have to care much about the OPTIONS method. Must I really explicitly specify this method in order for PUT, DELETE, OPTIONS to work?

Thanks for all help!

Community
  • 1
  • 1
Jim Aho
  • 9,932
  • 15
  • 56
  • 87
  • This solution worked for me I was facing a similar issue. http://stackoverflow.com/questions/42233836/cors-issue-on-put/42234966#42234966 – Leonardo Wildt Feb 14 '17 at 19:51

0 Answers0