jQuery AJAX CORS with ASP.NET WCF service not working despite web.config entries
Enabling CORS to true in backend server where service is hosted should ideally solve the problem. However there is one more way... You can have a wrapper in between jQuery code and WCF service ( Note: It's one of the approach you have to suggest in the team when you do not have the access to modify for example htaccess file in apache where we set the CORS to have access to other domain accessing our service). So the approach goes like this....
jQuery Code -> Wrapper (Webmethod in .NET) -> WCF service
jQuery code and Wrapper resides in the same domain. jQuery calls webmethod which in turn fire a call to respective WCF service method to get the data. The downfall of this approach is that the request traverse through one more layer, the reason why I have mentioned Note in the beginning.
Your <customHeaders>
web.config section is set up for CORS requests without credentials. You need a different configuration to allow CORS requests with credentials:
Set an additional
Access-Control-Allow-Credentials
header totrue
.Access-Control-Allow-Origin
header cannot be set to*
. You have to return a case-sensitive match for the CORS request origin/host.
Source: 7.2 Resource Sharing Check (W3C Recommendation for Cross-Origin Resource Sharing)