1

I'm getting really frustrated with jsonp or cors etc.

jsonp results on jquery thinking it's an error if it's just a status code that comes back, and no body. It also thinks that an error code coming back should have an error with status 200 so you can't even determine which is which.

So then I try cors, and WebAPI is intercepting my DelegatingHandler on any options request somehow and with the results that get fired back, all major browsers never go past the options request.

So then i put a ton of stuff in my web.config to force the headers:

  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="https://beta.mobilemone.com" />
    <add name="Access-Control-Allow-Headers" value="content-type, accept, authorization, origin, referer, user-agent" />
    <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
    <add name="Access-Control-Allow-Credentials" value="true"/>
    <add name="Access-Control-Max-Age" value="1728000"/>
  </customHeaders>

Which gets it further, but still gets a "cancelled" result on the jquery ajax request that finally gets called.

How do I get cors to work properly with web api?

Thanks!

1
  • Further to this, it appears that the calls are actually executing on the server, but being cancelled on the client side without getting the result. Commented Dec 12, 2012 at 23:30

1 Answer 1

2

Try removing the <add name="Access-Control-Allow-Credentials" value="true"/> setting. This is going to cause problems if your client doesn't also set .withCredentials = true.

Also try changing the Access-Control-Allow-Origin header to:

<add name="Access-Control-Allow-Origin" value="*" />

If these two tips don't work, can you include your JavaScript code along with a trace of the request/response headers?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.