Thursday, February 18, 2016

XMLHttpRequest cannot load Request header field dataType is not allowed by Access-Control-Allow-Headers in preflight response.

Error:

When POST to WebMethod - ASP.NET

XMLHttpRequest cannot load Request header field dataType is not allowed by Access-Control-Allow-Headers in preflight response.

Solution: 

Add to web.config:


    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type, accessToken, signedInUserId, x-requested-with" />
      </customHeaders>
    </httpProtocol>