- Add js cross-domain access.
Add (IServiceCollection services) in Startup.cs file public IServiceProvider ConfigureServices
services.AddCors( options => options.AddPolicy( "AlloweDomain", builder => builder .WithOrigins( // App:CorsOrigins in appsettings.json can contain more than one address separated by comma. _appConfiguration["App:CorsOrigins"] .Split(",", StringSplitOptions.RemoveEmptyEntries) .Select(o => o.RemovePostFix("/")) .ToArray() ) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() ) );
Adding allowing cross-domain Controller. You can also add all inherited Controller allows inherited classes in ControllerBase in.
[EnableCors("AlloweDomain")] public class FileGetController : ServiceControllerBase { }
In appsettings.json added to allow access to the domain name.
"App": { "CorsOrigins": "http://localhost:4200,http://localhost:8080,http://localhost:8081,https://www.baidu.com" },