Beispiel #1
0
        /// <summary>
        /// Registra as configurações de Cors da aplicação.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration">configuração do aplicativo</param>
        public static void AddCorsConfigurations(this IServiceCollection services, IConfiguration configuration)
        {
            ICorsSettings defaultSettings = configuration.GetSection(CorsSettings.DefaultCorsSettings).Get <CorsSettings>();
            ICorsSettings signalRSettings = configuration.GetSection(CorsSettings.SignalRCorsSettings).Get <CorsSettings>();

            services.AddCors(setup =>
            {
                setup.AddPolicy(CorsSettings.DefaultCorsSettings,
                                builder => builder.WithOrigins(defaultSettings.AllowedOrigins)
                                .WithMethods(defaultSettings.AllowedMethods)
                                .AllowAnyHeader());

                setup.AddPolicy(CorsSettings.SignalRCorsSettings,
                                builder => builder.WithOrigins(signalRSettings.AllowedOrigins)
                                .WithMethods(signalRSettings.AllowedMethods)
                                .AllowAnyHeader()
                                .AllowCredentials());
            });
        }
 public CorsOptionsMiddleware(RequestDelegate next, IHostingEnvironment environment, ICorsSettings settings)
 {
     _next        = next;
     _environment = environment;
     _settings    = settings;
 }