Пример #1
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     app.UseCors("AllowAll");
     RuntimeStartup.Configure(app, env);
     app.UseAuthentication();
     app.UseMvc();
 }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options => options.AddPolicy("AllowAll",
                                                          builder =>
                                                          builder
                                                          .AllowAnyMethod()
                                                          .AllowAnyOrigin()
                                                          .AllowAnyHeader()));

            RuntimeStartup.ConfigureServices(services, Configuration, (options, connectionStringName)
                                             => options.UseNpgsql(Configuration.GetConnectionString(connectionStringName)));
            services.RegisterEfCore();

            services.AddControllers()
            .AddNewtonsoftJson(options =>
            {
                options.UseMemberCasing();
            })
            .AddJsonOptions(jsonOptions =>
            {
                jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null;
            });

            services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority            = Configuration.GetSection("AuthAuthority").Get <string>();
                options.RequireHttpsMetadata = false;
            });
        }
Пример #3
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 {
     app.UseCors("AllowAll");
     app.UseRouting();
     app.UseAuthentication();
     RuntimeStartup.Configure(app, env);
     app.UseEndpoints(endpoints =>
     {
         endpoints.MapControllers();
     });
 }
Пример #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options => options.AddPolicy("AllowAll",
                                                          builder =>
                                                          builder
                                                          .AllowAnyMethod()
                                                          .AllowAnyOrigin()
                                                          .AllowAnyHeader()));

            services.AddDbContext <MetadataDbContext>(options =>
            {
                var provider = Configuration.GetSection("EfProvider").Get <string>();
                switch (provider)
                {
                case "MySql":
                    options.UseMySql(
                        Configuration.GetConnectionString("Engine_MySql"));
                    return;

                case "SqlServer":
                    options.UseSqlServer(
                        Configuration.GetConnectionString("Engine_SqlServer"));
                    return;

                default:
                    throw new NotImplementedException($"The provider {provider} is not implemented yet.");
                }
            });

            RuntimeStartup.ConfigureServices(services, Configuration);
            services.RegisterEfCore();

            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);

            services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority            = "http://localhost:5001";
                options.RequireHttpsMetadata = false;
            });
        }