Company A mobile back end of the project used to
Webapi
Project construction to the extranet environment a common app developer has encountered a problem invoking the test interface
interface does not allow cross-domain calls
。 Access to the information understand
Origin policy principle based on request header value
Origin
With the response header value
Access-control-allow-origin
To determine whether the call is allowed
Workaround
1.ajax using jsonp
JSONP is to add the callback function parameter value through the request parameter. Webapi receive callback function parameter value return data is no longer purely JSON, but is based on the callback function parameter value
JS method call, so that the same origin policy is avoided
You need to Webapi rewrite the JSON serialization method.
Jsonmediatypeformatter
2. For terminals such as iOS,
Simple method to configure HTTP headers for IIS directly
This method is simple, fast and unsafe.
Exposed all the
3. Override the Web API's
Delegatinghandler
Adding a custom HTTP header
4. Leveraging the Web API's own extensions
Microsoft ASP. NET Web API 2 Cross-origin support
: