Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ToDoListContext context, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(configure => configure.Run(async httpContext =>
                {
                    var feature = httpContext.Features.Get <IExceptionHandlerFeature>();
                    if (feature != null)
                    {
                        var logger = loggerFactory.CreateLogger("Exception Error");
                        logger.LogError(500, feature.Error, feature.Error.Message);
                        httpContext.Response.StatusCode = 500;
                        await httpContext.Response.WriteAsync(feature.Error.Message);
                    }
                })


                                        );
            }

            context.SeedDatabase();
            app.UseIpRateLimiting();
            app.UseResponseCaching();
            app.UseHttpCacheHeaders();

            app.UseMvc();
        }