core.net cross-domain

First, in the web.config <system.webServer> </ system.webServer> Add httpProtocol disposed intermediate cross-domain.

<httpProtocol>
       <customHeaders>
             <add name="Access-Control-Allow-Origin" value="*" />
             <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
             <add name="Access-Control-Allow-Headers" value="Content-Type" />
       </customHeaders>
</httpProtocol>

Second, add the following code ConfigureServices method StartUp class:

// allow one or more sources across domains 
services.AddCors (Options => 
{ 
      options.AddPolicy ( " CustomCorsPolicy " , Policy => 
      { 
            // settings allow cross-domain sources, there may be a plurality, '' spacer open 
            policy.WithOrigins ( " HTTP: // localhost: 21632 " , " HTTP: // localhost: 24661 " ) 
            .AllowAnyHeader () 
            .AllowAnyMethod () 
            .AllowCredentials (); 
      }); 
});

Third, the Configure modifying code is as follows:

// set a specific ip is configured to allow cross-domain CustomCorsPolicy in ConfigureServices method of cross-domain policy name 
app.UseCors ( " CustomCorsPolicy " );

Fourth, before or API controller MVC in Action added:

 [EnableCors("CustomCorsPolicy")]

May be added in the Action Code

 Response.Headers.Add("Access-Control-Allow-Origin", "*");

 

Reference website: https://www.cnblogs.com/dotnet261010/p/10177166.html

                 https://www.cnblogs.com/mabelhua/p/10131156.html

                https://www.cnblogs.com/willingtolove/p/11175599.html

                https://www.cnblogs.com/lonelyxmas/p/12070762.html

Guess you like

Origin www.cnblogs.com/yibinboy/p/12326835.html