// 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) { App = app; loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseSession(); app.UseCookieAuthentication(new CookieAuthenticationOptions() { AuthenticationScheme = "CookieAuth", LoginPath = new PathString("/Login/"), AccessDeniedPath = new PathString("/error.html"), AutomaticAuthenticate = true, AutomaticChallenge = true }); app.UseCoreProfiler(true); app.UseMvc(routes => { // Areas support routes.MapRoute( name: "areaRoute", template: "{area}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); //*** Initialize the DB ***// //if (env.EnvironmentName == "Development") // InitializeBasicDb(app.ApplicationServices).Wait(); //将插件数据写入数据库 using (EvolutionDBContext dbContext = app.ApplicationServices.GetService <EvolutionDBContext>()) { app.InitFreameworkDbData(app.ApplicationServices, env.WebRootPath, dbContext); //add plugin info to MainDb foreach (var p in pluginManager.PluginAssemblies) { try { var exist = dbContext.Plugins.CountAsync(t => t.Id == p.Id).Result; if (exist == 0) { dbContext.Add(p); } } catch { continue; } } //exec db pluginManager.MeragePluginDBStruct(app.ApplicationServices); pluginManager.InitPluginData(dbContext, app.ApplicationServices, env.WebRootPath); dbContext.SaveChanges(); } }
// 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) { App = app; loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); loggerFactory.AddNLog(); env.ConfigureNLog("nlog.config"); ILogger _logger = loggerFactory.CreateLogger("MyApplication.Startup"); _logger.LogInformation("系统启动【开始】"); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseCors(policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); //提供jwttoken服务 app.GenJWTEndpoint(Configuration); //配置token验证 app.ConfigureJwtAuth(Configuration); //app.UseMiddleware<ResourceFilterMiddleware>(); app.UseCoreProfiler(true); app.UseMvc(routes => { // Areas support routes.MapRoute( name: "areaRoute", template: "{area}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); //*** Initialize the DB ***// //if (env.EnvironmentName == "Development") // InitializeBasicDb(app.ApplicationServices).Wait(); //将插件数据写入数据库 EvolutionDBContext dbContext = app.ApplicationServices.GetService <EvolutionDBContext>(); _logger.LogInformation("初始化测试数据【开始】"); app.InitFreameworkDbData(app.ApplicationServices, env.WebRootPath, dbContext); _logger.LogInformation("初始化测试数据【完成】"); //add plugin info to MainDb foreach (var p in pluginManager.PluginAssemblies) { _logger.LogInformation(string.Format("开始处理插件[{0}]数据库", p.Name)); try { var exist = dbContext.Plugins.CountAsync(t => t.Id == p.Id).Result; if (exist == 0) { dbContext.Add(p); } } catch { continue; } } _logger.LogInformation("合并插件数据库结构到主数据库"); //exec db pluginManager.MeragePluginDBStruct(app.ApplicationServices); _logger.LogInformation("初始化插件数据"); pluginManager.InitPluginData(dbContext, app.ApplicationServices, env.WebRootPath); dbContext.SaveChanges(); _logger.LogInformation("系统启动【完成】"); }