// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "my_books v1")); } app.UseHttpsRedirection(); app.UseRouting(); //Authentication & Authorization app.UseAuthentication(); app.UseAuthorization(); //Exception Handling app.ConfigureBuildInExceptionHandler(loggerFactory); //app.ConfigureCustomExceptionHandler(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); //AppDbInitializer.Seed(app); AppDbInitializer.SeedRoles(app).Wait(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var logger = services.GetRequiredService <ILogger <Program> >(); try { var context = services.GetRequiredService <AspergillosisContext>(); var context2 = services.GetRequiredService <ApplicationDbContext>(); var hostingEnvironment = services.GetRequiredService <IHostingEnvironment>(); AspergillosisDatabaseSeeder.SeedDatabase(hostingEnvironment, context); AppDbInitializer.Initialize(context2); } catch (Exception ex) { logger.LogError(ex, "An error occurred while seeding the database."); } finally { } } host.Run(); }
// 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) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); AppDbInitializer.Initialize(app.ApplicationServices.GetService <AppDbContext>()); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var env = host.Services.GetService <IHostingEnvironment>(); if (env.IsDevelopment()) { var services = scope.ServiceProvider; try { var ctx1 = services.GetRequiredService <AppDbContext>(); ctx1.Database.Migrate(); AppDbInitializer.Initialize(ctx1); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred creating the DB."); throw; } } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BookStore v1")); } app.UseHttpsRedirection(); app.UseCors("TCAPolicy"); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(env.WebRootPath, "images")), RequestPath = "/images" }); AppDbInitializer.Seed(app); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <ApplicationUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); AppDbInitializer.SeedUser(userManager); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); // Added for Identity ===================> app.UseAuthentication(); app.UseAuthorization(); // <====================================== app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); // Razor pages added for Identity endpoints.MapRazorPages(); }); app.UseRewriter(new RewriteOptions().AddRedirectToHttpsPermanent()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); AppDbInitializer.SeedAsync(app).GetAwaiter(); }
// 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) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Order/Error"); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859 try { using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>() .CreateScope()) { serviceScope.ServiceProvider.GetService <ApplicationDbContext>() .Database.Migrate(); } } catch { } } app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseIdentity(); app.UseSession(); // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseGoogleAuthentication(options => { options.ClientId = "450267970917-qf25gkmpjqe177t8c1jfu78dtdgs5p30.apps.googleusercontent.com"; options.ClientSecret = "Xyc5VhAJX8SWLxffocOpT13C"; }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Order}/{action=Index}/{id?}"); }); AppDbInitializer.Initialize(app.ApplicationServices); }
void Application_Start(object sender, EventArgs e) { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutoMapConfig.RegisterMaps(); AppDbInitializer.Init(); }
public ActionResult Upload() { try { string id = Request.Form["id"]; string path = PathName(id); foreach (string file in Request.Files) { var upload = Request.Files[file]; if (upload != null) { AppDbInitializer appDbInitializer = new AppDbInitializer(); List <FileExtension> fileExtensions = directoryContext.FileExtensions.ToList(); string name = upload.FileName; string pathFileName = path + "\\" + name; if (System.IO.File.Exists(pathFileName) == true) { upload.SaveAs(pathFileName); return(Json("Файл успешно заменен!")); } else { upload.SaveAs(pathFileName); int typeCodeOfTheFile = appDbInitializer.GetTypeCodeOfTheFile(fileExtensions, name); string content = appDbInitializer.GetContent(pathFileName); string description = appDbInitializer.GetDescription(content); directoryContext.Files.Add(new Files() { Name = name, FolderCode = Convert.ToInt32(id), TypeCodeOfTheFile = typeCodeOfTheFile, Content = content, Description = description, }); directoryContext.SaveChanges(); } } } return(Json(true)); } catch (Exception e) { return(Json(e.Message)); } }
protected void Application_Start() { //Database.SetInitializer(new AppDbInitializer()); var init = new AppDbInitializer(); init.InitializeDatabase(new ApplicationContext()); //var db = new ApplicationContext(); //db.Database.Initialize(true); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <AppUser> userManager, RoleManager <IdentityRole> roleManager) { app.UseAuthentication(); //app.UseCors(builder => builder // .AllowAnyOrigin() // .AllowAnyMethod() // .AllowAnyHeader() // .AllowCredentials()); app.UseMvcWithDefaultRoute(); AppDbInitializer.Seed(userManager, roleManager).Wait(); }
// 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, IAppDbContext dataContext) { AppDbInitializer.Initialize(dataContext); loggerFactory.AddNLog(); app.AddNLogWeb(); app.UseMiddleware(typeof(ExceptionHandlingMiddleware)); app.UseMvc(); var cpuMonitorUnitOfWork = new UnitOfWork(dataContext); var cpuMonitor = new CpuMonitor(loggerFactory.CreateLogger <CpuMonitor>(), cpuMonitorUnitOfWork, new CpuStatusRepository(cpuMonitorUnitOfWork)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseDeveloperExceptionPage(); app.UseStatusCodePages(); app.UseStaticFiles(); app.UseSession(); app.UseRouting(); app.UseEndpoints(endpoints => { //endpoints.MapGet("/", async context => //{ // await context.Response.WriteAsync("Hello World!"); //}); endpoints.MapControllerRoute ( name: "default", pattern: "{controller=Main}/{action=Index}/{id?}" ); endpoints.MapControllerRoute ( name: "admin", pattern: "{controller=Admin}/{action=Index}" ); endpoints.MapControllerRoute ( name: "salads", pattern: "{controller=Main}/{action=Index}" ); endpoints.MapControllerRoute ( name: "pizzas", pattern: "{controller=Main}/{action=Index}" ); endpoints.MapControllerRoute ( name: "list", pattern: "{controller=Dish}/{action=List}" ); }); using (var scope = app.ApplicationServices.CreateScope()) { AppDbContext context = scope.ServiceProvider.GetRequiredService <AppDbContext>(); AppDbInitializer.Initial(context); } }
protected override void Seed(AppContext context) { AppDbInitializer.GetUsersFromXml(context, _path); // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // }
public ActionResult DeleteFolder(string id) { string path = PathName(id); try { Directory.Delete(path, true); AppDbInitializer appDbInitializer = new AppDbInitializer(); appDbInitializer.InitializeDatabase(new DirectoryContext()); return(Json(true)); } catch (Exception e) { return(Json(e.Message)); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "netcorewebapi v1")); } app.UseHttpsRedirection(); app.UseRouting(); app.UseCors("AllowOrigin"); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); AppDbInitializer.seed(app); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "book_service v1")); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); // Added : AppDbInitializer.Seed(app); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseRouting(); app.Map(new PathString(""), client => { var clientPath = Path.Combine(Directory.GetCurrentDirectory(), "./ClientApp/dist"); StaticFileOptions clientAppDist = new StaticFileOptions() { FileProvider = new PhysicalFileProvider(clientPath) }; client.UseSpaStaticFiles(clientAppDist); client.UseSpa(spa => { spa.Options.DefaultPageStaticFileOptions = clientAppDist; }); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); }); using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { //Seed method AppDbInitializer.Seed(serviceScope); } }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); //CreateWebHostBuilder(args).Build().Run(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <AppDbContext>(); AppDbInitializer.InitializeAsync(context, services).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured while seeding the database."); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { // dev excetion page app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // redirect to https app.UseHttpsRedirection(); // use static files app.UseStaticFiles(); app.UseRouting(); // auths app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { // admin area endpoints.MapAreaControllerRoute( "admin", "admin", "Admin/{controller=Home}/{action=Index}/{id?}"); // normal MVC endpoints.MapControllerRoute( "default", "{controller=Home}/{action=Index}/{id?}"); }); // initialize db AppDbInitializer.Initialize(app.ApplicationServices); }
// 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) { // Dependency Injection InitializeContainer(app); // Logging loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // MVC app.UseMvc(); app.UseDefaultFiles(); app.UseStaticFiles(); // Entity Framework AppDbInitializer.Initialize(app.ApplicationServices); // Mapping Infrastructure.AutoMapper.Register(); app.UseSwagger(); app.UseSwaggerUi(); }
public static async Task Main(string[] args) { var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); try { logger.Debug("Main started"); logger.Error("Test error"); var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <Profile> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var initData = services.GetRequiredService <IAppDbInitData>(); await AppDbInitializer.InitializeAsync(userManager, rolesManager, initData); } catch (Exception ex) { logger.Error(ex, "An error occurred while seeding the database."); } } host.Run(); } catch (Exception exception) { logger.Error(exception, "Stopped program because of exception"); throw; } finally { NLog.LogManager.Shutdown(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context)//, RoleManager<IdentityRole> roleManager,UserManager<User> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); //app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions //{ // HotModuleReplacement = true //}); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); AppDbInitializer.Initialize(context); }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); AppDbInitializer.SeedUsers(); }
// 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, AppDbInitializer dbInitializer, CloudMedicDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors("AllowAll"); app.UseAuthentication(); app.UseMvc(); IServiceProvider serviceProvider = app.ApplicationServices.CreateScope().ServiceProvider; var dbContext = (CloudMedicDbContext)serviceProvider.GetRequiredService <CloudMedicDbContext>(); context.Database.Migrate(); dbInitializer.Seed().Wait(); }
protected override void Seed(Models.AppModel context) { AppDbInitializer.PopulateContext(context); }