[Problem] recording pit father's cross-domain issues

About cross-domain problem is a commonplace problem. There is a large online solutions. Here I just record what treatment method cross-domain problems encountered in the project.

First, the project encountered problems:

  Initial: that is a simple cross-domain problem, a configuration in web.config or by adding Cors on the line.

web.config plus configuration: <system.webServer> node plus some configuration

 

 

 

Or tags plus Cors

 

Logically, these two solutions can solve the question raised cross-domain. But it will not work in this project.

Call interface being given. Dare to believe!

报错:The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

Later he continues to study a little, because the client call interface to set up a verification request carries identity information that is passed Cookie information call interface. Cors configuration or added in the code does not work in the press between web.config added.

 

It is to be understood as a http protocol or CORS rules.

When the request is set in withCredentials: true, that is, when the request carries the information to verify identity,

response of Access-Control-Allow-Origin: *, (but should have a status request filtering)

Otherwise, the request will fail.

 

Find where the problem is simple.

This time the first thought is not the solution to pass Cookie, replaced by JWT verification Token. Single Considering that the project is already running in the. abandon

Another solution is to continue to increase as the web.config configuration

 

 

 Into this, the client call interface successfully.

 

Which call interface back to visit twice, once Method for the OPTIONS,

You may be configured to "Access-Control-Max-Age", indicating that the 86,400 seconds, no need to transmit pre-check request, the results can be cached

Module can be extended to intercept a request OPTIONS Method returned directly to

Code:

 

 You need to configure the module in the web.config

 

 

End.

Remember the first time to write a blog.

Rub one.

Forgive me.

Guess you like

Origin www.cnblogs.com/SnowXia/p/12055811.html