using Microsoft.Extensions.DependencyInjection; using Znyc.CloudCar.Configuration; namespace Znyc.CloudCar.Core.Config { public static class CoreSetup { public static void AddCoresSetup(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddCors(c => { if (!AppSettingsConstVars.CorsEnableAllIPs) { c.AddPolicy(AppSettingsConstVars.CorsPolicyName, policy => { policy.WithOrigins(AppSettingsConstVars.CorsIPs.Split(',')); policy.AllowAnyHeader(); policy.AllowAnyMethod(); policy.AllowCredentials(); }); } else { //允许任意跨域请求 c.AddPolicy(AppSettingsConstVars.CorsPolicyName, policy => { policy.SetIsOriginAllowed((host) => true) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); } }); } } }