Come straight to the dry.
The program works under a single IIS, and the domain name (load balancer) opens up various cross-domains. Under the study, a solution can be generally used as long as the following conditions are met:
Conditions are:
1. HTTP method: Methods other than Get,head,post
2. Use the Post method, and use application/x-www-form-urlencoded, Multipart/form-data, or text/plain other than Content-type, for example: Send XML as POST , JSON, etc.
3. Use a custom header
Solution:
Remove the optionsverbhandler Handle Mapping under IIS,
Or add in the Webconfig type:
<system.webServer>"optionsverbhandler" / > <!--and
View Codeor intercept the options request directly,
if (Request. Method.method==httpmethod.options.method) { return base. SendAsync (Request, CancellationToken). ContinueWith ( task = {return request. Createresponse (Httpstatuscode.ok); } ); }
The reason for this is that AJAX requests always send an options before sending a normal request. While IIS default to the options of the direct interception, do not do processing, directly return, but did not include the Access-control-allow-origin Header, so the request failed, there is no second normal request.
Ajax JSON cross-domain Request service (WEBAPI,WCF or other)