Ejemplo 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, ILoggerFactory loggerFactory)
        {
            //var result = string.IsNullOrEmpty(_testSecret) ? "Null" : "Not Null";
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync($"Secret is {result}");
            //});

            app.UseSession();
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseStaticFiles();
#pragma warning disable CS0618 // 类型或成员已过时
            app.UseIdentity();
#pragma warning restore CS0618 // 类型或成员已过时

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            // Loading sample data.
            using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory> ().CreateScope()) {
                var  dbContext  = serviceScope.ServiceProvider.GetService <BestStoreDbContext> ();
                bool HasCreated = dbContext.Database.EnsureCreated();
                if (HasCreated)
                {
                    SampleDataInitializer dbInitializer = new SampleDataInitializer(dbContext);
                    dbInitializer.LoadBasicInformationAsync().Wait();
                    dbInitializer.LoadSampleDataAsync().Wait();
                }
            }
        }