0

I'm performing a cross-domain POST using jQuery ajax to call an ASP.net 4.5 WebAPI site:

$.support.cors = true;
$.ajax("http://mydomain/WebApi/api/authentication/", { type: "post", data: json, contentType: "application/json" });

Here is my server method:

public class AuthenticationController : ApiController
{

    // Login or logout the user.
    // POST api/authentication with login or logout data object
    public HttpResponseMessage Post(object data)
    {
        return ProcessAction(data);
    }
}

I've set the headers on remote server:

Access-Control-Allow-Origin: *

Access-Control-Allow-Methods: POST,GET, OPTIONS

When I execute the code, I get a 405 Method Not Allowed - The requested resource does not support http method 'GET'.

The method I am calling works fine if called from the same domain.

Additionally, if I remove the contentType: "application/json" option, I get a 500 Server Error.

It appears the contentType option has something to do with the problem, but I am not sure.

Any suggestions or advice are greatly appreciated!

Thanks.

Community
  • 1
  • 1
Swisher Sweet
  • 769
  • 11
  • 33
  • Please attach your server side code. Possible duplicate of http://stackoverflow.com/q/11005788/2678731 – losnir Aug 16 '13 at 00:29
  • @losnir thanks for the link. I don't believe this is my problem as the POST works if I run the server code on the same domain (that is I run the javascript code from the same site use a relative URL (/api/authentication/) instead of the cross-domain URL. – Swisher Sweet Aug 16 '13 at 15:48
  • Some helping points: 1. Why are you setting `$.support.cors`? 2. What is the JavaScript environment? 3. Attaching `ProcessAction` would be helpful too. 4. Inspect your response headers (using FireBug \ Chrome Development Tools), what are you getting? 5. What is the `[AcceptVerbs]` value of your `HttpMethod`? – losnir Aug 16 '13 at 16:50

0 Answers0