Cross-domain AJAX requests are more complicated that that:
AJAX Cross Domain | Cross-Origin Request | jQuery CORS[
^]
The XHR component will initially make a "pre-flight" request to the server, without any data or custom headers, to ensure that the CORS settings on the server will allow the request.
Your server is unconditionally throwing an exception for every request, so the pre-flight request fails, and the real request is never sent.
Try changing your code to check that
HttpContent.Current.Request.HttpMethod
is set to "POST" before looking for your custom header.
You'll also need to make sure you're sending the correct CORS headers in the response.
Enabling Cross-Origin Requests in ASP.NET Web API 2 | Microsoft Docs[
^]