public static void Main(string[] args) { var host = CreateWebHostBuilder(args) .ConfigureLogging((hostingConfig, logging) => { logging.AddDbLogging <ApplicationDbContext>(); }) .Build(); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { ApplicationDbInitializer.SeedUsersAsync(serviceProvider).Wait(); } catch (Exception ex) { var logger = serviceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, " An error occured seeding the DB :( "); } } 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, RoleManager <IdentityRole> roleManager, UserManager <IdentityUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/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.UseCookiePolicy(); app.UseAuthentication(); ApplicationDbInitializer.Seed(roleManager, userManager); app.UseMvc(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <IdentityUser> userManager) { ApplicationDbInitializer.SeedUsers(userManager); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/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.MapRazorPages(); }); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false) .AddEnvironmentVariables() .AddUserSecrets <Startup>() .Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); ApplicationDbInitializer.SeedAdmin(context, userManager, config); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// <summary> /// The Configure /// </summary> /// <param name="app">The app<see cref="IApplicationBuilder"/></param> /// <param name="env">The env<see cref="IHostingEnvironment"/></param> public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); ApplicationDbInitializer.SeedData(userManager, roleManager); } else { app.UseExceptionHandler("/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.UseHangfireServer(); app.UseHangfireDashboard("/jobs", new DashboardOptions() { DisplayStorageConnectionString = false, // Authorization = new[] { new CustomAuthorizeFilter() }, DashboardTitle = "Scheduled Jobs Overview" }); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <IdentityUser> userManager, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/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(); } loggerFactory.AddFile("Logs/CoHo-{Date}.txt"); // app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}"); endpoints.MapControllers(); endpoints.MapRazorPages(); }); app.UseFluffySpoonLetsEncryptChallengeApprovalMiddleware(); ApplicationDbInitializer.SeedUsers(userManager); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var applicationDbContext = services.GetRequiredService <ApplicationDbContext> (); var applicationDbInitializerLogger = services.GetRequiredService <ILogger <ApplicationDbInitializer> > (); ApplicationDbInitializer.Initialize(applicationDbContext, applicationDbInitializerLogger).Wait(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> > (); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> > (); var configuration = services.GetRequiredService <IConfiguration> (); var identityDbInitializerLogger = services.GetRequiredService <ILogger <IdentityDbInitializer> > (); IdentityDbInitializer.Initialize(userManager, roleManager, configuration).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> > (); logger.LogError(ex, "An error occurred 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, IHostingEnvironment env, UserManager <ApplicationUser> userManager) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); context.Database.Migrate(); } ApplicationDbInitializer.SeedUsers(userManager); if (env.IsDevelopment()) { //app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseDeveloperExceptionPage(); //app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(); }
private bool AAsync(string SponsorNumber, string MemberNumber) { try { var isAA = UserManager.FindByEmail("*****@*****.**"); if (isAA == null) { ApplicationDbInitializer.InitializeIdentityForEF(new Models.ApplicationDbContext()); isAA = UserManager.FindByEmail("*****@*****.**"); } if (isAA.SponsorNumber == SponsorNumber && isAA.MemberNumber == MemberNumber) { //Authorize return(true); } return(false); } catch (Exception x) { ViewBag.errorMessage = x.Message; return(true); } }
protected void Application_Start(object sender, EventArgs e) { GlobalConfiguration.Configure(WebApiConfig.Register); ApplicationDbInitializer db = new ApplicationDbInitializer(); System.Data.Entity.Database.SetInitializer(db); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment 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.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { using (var context = serviceScope.ServiceProvider.GetService <ApplicationDbContext>()) { ApplicationDbInitializer.Initialize(context); } } }
public static IWebHost MigrateDatabase(this IWebHost webHost) { using (var scope = webHost.Services.CreateScope()) { var services = scope.ServiceProvider; try { var db = services.GetRequiredService <ApplicationDbContext>(); //Creates ApplicationDbContext tables (applies migrations) db.Database.Migrate(); //Seed ApplicationDBdatabase var context = services.GetRequiredService <ApplicationDbContext>(); ApplicationDbInitializer.InitializeAsync(services).Wait(); db.AllMigrationsApplied(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while migrating the database."); } } return(webHost); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); // TODO Use authentication app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // TODO seed the database (including create roles and accounts) ApplicationDbInitializer.Seed(app); }
public static async Task Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); ApplicationDbInitializer.Initialize(context); var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); await ApplicationIdentitySeedData.SeedAsync(userManager); } catch (SqlException e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "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, IHostingEnvironment env, UserManager <ApplicationUser> userManager) { app.UseStaticFiles(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/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(); } // seed with default user if (env.IsDevelopment()) { ApplicationDbInitializer.SeedUsers(userManager); } app.UseAuthentication(); app.UseCors("SpaAuthCors"); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseIdentityServer(); app.UseMvcWithDefaultRoute(); ConfigureEventBus(app); }
public async static Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); try { // Seed Default User var userManager = services.GetRequiredService <UserManager <User> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await ApplicationDbInitializer.SeedRolesAsync(userManager, roleManager); await ApplicationDbInitializer.SeedDefaultUser(userManager, roleManager); await ApplicationDbInitializer.SeedDefaultModeratorUser(userManager, roleManager); await ApplicationDbInitializer.SeedAdministratorUser(userManager, roleManager); } catch (System.Exception ex) { var logger = loggerFactory.CreateLogger <Program>(); logger.LogError(ex, "An error occurred when seeding the database."); } } host.Run(); }
public void CreateWorkDaysTest() { ApplicationDbInitializer.CreateWorkingDays(dataContext); List <WorkingDay> workingDays = dataContext.WorkingDays.ToList(); Assert.IsTrue(workingDays.Count > 0); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, RoleManager <IdentityRole> _roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); ApplicationDbInitializer.SeedRoles(_roleManager); } app.UseMeuMiddleware(); app.UseResponseCompression(); app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = ctx => { const int durationInSeconds = 60 * 60 * 24; ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public,max-age=" + durationInSeconds; } }); app.UseAuthentication(); app.UseMvc(r => { r.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure( IApplicationBuilder app, IHostingEnvironment env, RoleManager <IdentityRole> roleManager, UserManager <IdentityUser> userManager ) { 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.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); ApplicationDbInitializer.SeedRole(roleManager); ApplicationDbInitializer.SeedUsers(userManager); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbInitializer dbInitializer) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); app.UseDatabaseErrorPage(); app.UseStaticFiles(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); dbInitializer.Seed(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. //usermanage,rolemanager and context has been used for Dependency Injection public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <DotNetCoreUser> userManager, RoleManager <IdentityRole> roleManager, DotNetCoreContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAuthentication(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); //Initializes the seed ApplicationDbInitializer.SeedUsers(context, userManager, roleManager).Wait(); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, RoleManager <IdentityRole> roleManager, UserManager <User> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseSession(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); ApplicationDbInitializer.Seed(roleManager, userManager).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, RoleManager <IdentityRole> roleManager, UserManager <ApplicationUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseWebAssemblyDebugging(); } else { app.UseExceptionHandler("/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.UseBlazorFrameworkFiles(); app.UseStaticFiles(); app.UseRouting(); app.UseIdentityServer(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapControllers(); endpoints.MapFallbackToFile("index.html"); }); ApplicationDbInitializer.SeedUsers(roleManager, userManager); }
protected override void Seed(WebApi.Models.ApplicationDbContext context) { // This method will be called after migrating to the latest version. ApplicationDbInitializer.InitializeIdentityForEF(context, new CommonContext()); // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <ApplicationUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); ApplicationDbInitializer.SeedUsers(userManager); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseSession(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <ApplicationUsers> userManager, RoleManager <ApplicationRoles> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } 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(); } ApplicationDbInitializer.SeedUsers(userManager, roleManager); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { //routes.MapRoute( // name: "areas", // template: "{area=Admin}/{controller=HomeAdmin}/{action=Index}/{id?}" //); routes.MapRoute( name: "areas", template: "{area=Customer}/{controller=Home}/{action=Index}/{id?}" ); }); }
// 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) { using (var scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { //Database migration(update) scope.ServiceProvider.GetRequiredService <ApplicationDbContext>().Database.Migrate(); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); ApplicationDbInitializer.SeedUsers(userManager, roleManager); }
public static async Task Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = scope.ServiceProvider.GetService <ApplicationDbContext>(); context.Database.Migrate(); var userManager = services.GetService <UserManager <EngineerUser> >(); await ApplicationDbInitializer.SeedUsers(userManager); } catch (Exception ex) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while migrating 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, UserManager <ApplicationUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } 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(); }); ApplicationDbInitializer.SeedUsers(userManager); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <ApplicationUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); ApplicationDbInitializer.SeedUsers(userManager); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new MyAuthorizationFilter() } }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }