Exemple #1
0
        //IHostingEnvironment env
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, YourDbContextSeedData seeder)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            /*else
             * {
             *  app.UseExceptionHandler(builder =>
             *  {
             *      builder.Run(async context =>
             *      {
             *          context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
             *          context.Response.ContentType = "text/html";
             *          var ex = context.Features.Get<IExceptionHandlerFeature>();
             *          if (ex != null)
             *          {
             *              var err = $"<h1>Error: {ex.Error.Message}</h1>{ex.Error.StackTrace}";
             *              await context.Response.WriteAsync(err).ConfigureAwait(false);
             *          }
             *      });
             *  });
             * }*/

            seeder.SeedAdminUser();
            seeder.SeedProducts();

            app.UseCors("CorsPolicy");
            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            //app.UseMvc();
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext dataContext, YourDbContextSeedData seeder)
        {
            // migrate any database changes on startup (includes initial db creation)
            dataContext.Database.Migrate();

            app.UseRouting();

            seeder.SeedAdminUser();

            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints => endpoints.MapControllers());
        }