// 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 , RoleManager <IdentityRole> roleManager , ApplicationDbContext dbContext ) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseSession(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); dbContext.Database.EnsureCreated(); IdentityInitializer.SeedRoles(roleManager); IdentityInitializer.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, ILoggerFactory loggerFactory, IdentityInitializer identitySeeder) { loggerFactory.AddConsole(_config.GetSection("Logging")); loggerFactory.AddDebug(); loggerFactory.AddFile("Logs/khodamooz-{Date}-log.txt"); app.Use(async(context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api/")) { context.Request.Path = "/index.html"; await next(); } }); app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); app.UseAuthentication(); app.UseMvcWithDefaultRoute(); app.UseDefaultFiles(); app.UseStaticFiles(); identitySeeder.Seed().Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <AppUser> userManager, RoleManager <AppRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStatusCodePagesWithReExecute("/Home/StatusCode", "?code={0}"); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); IdentityInitializer.SeedData(userManager, roleManager).Wait(); app.UseStaticFiles(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "areas", pattern: "{area}/{controller=Home}/{action=Index}/{id?}" ); endpoints.MapControllerRoute( name: "default", pattern: "{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 <IdentityUser> userManager, RoleManager <IdentityRole> roleManager) { // Seed identity database with admin role & account IdentityInitializer.SeedRoles(roleManager); IdentityInitializer.SeedAdminUser(userManager); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseSession(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); IdentityInitializer.Create(userManager, roleManager); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var serviceScope = host.Services.CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetRequiredService <BBITContext>(); await dbContext.Database.MigrateAsync(); var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <AppUser> >(); var identityInitializer = new IdentityInitializer(dbContext, userManager, roleManager); await identityInitializer.Initialize(); var env = serviceScope.ServiceProvider.GetRequiredService <IWebHostEnvironment>(); if (env.IsDevelopment()) { var testDbDataInitialization = new TestDbDataInitialization(dbContext); await testDbDataInitialization.Initialize(); } } await host.RunAsync(); }
public async void Configure( IApplicationBuilder app, IWebHostEnvironment env, MyIdentityContext context, UserManager <MyIdentityUser> userManager, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // Start the database with some users and clams. var initializer = new IdentityInitializer(context, userManager, roleManager); await initializer.Initialize(); app.UseSwaggerConfiguration(); app.UseHttpsRedirection(); app.UseRouting(); // Custom NetDevPack abstraction here! app.UseAuthConfiguration(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <User> userManager, RoleManager <Role> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); IdentityInitializer.SeedData(userManager, roleManager).Wait(); app.UseStaticFiles(); app.UseNToastNotify(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "areas", pattern: "{area}/{controller=Home}/{action=Index}/{id?}" ); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Login}/{id?}"); }); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { Task t; var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ArduinoContext>(); ArduinoInitializer.Initialize(context); var context2 = services.GetRequiredService <MeasurementContext>(); MeasurementInitializer.Initialize(context2); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); t = IdentityInitializer.InitializeAsync(userManager, rolesManager); t.Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public AccountController(UserManager <IdentityUser> userMgr, SignInManager <IdentityUser> signInMgr) { (userManager, signInManager) = (userMgr, signInMgr); // БД Identity будет заполняться каждый раз, когда создается // объект AccountController для обработки НТТР-запроса IdentityInitializer.Initialize(userMgr).Wait(); }
private async void InitializeDatabase(IApplicationBuilder app) { using (var scope = app.ApplicationServices.CreateScope()) { var services = scope.ServiceProvider; await IdentityInitializer.SeedAsync(services); } }
public void InitializerFailedTests() { var initializer = new IdentityInitializer(_validateDatabase, _userManager, _droneRoleValidator); _droneRoleValidator.CreateRoleAsync(Arg.Any <string>()).Returns(false); _droneRoleValidator.ExistRoleAsync(Arg.Any <string>()).Returns(false); _validateDatabase.EnsureCreated().Returns(true); Assert.Throws <Exception>(() => initializer.Initialize()); }
public IdentityInitializerTests() { _dbContextMock = new DbContextMock <ApplicationDBContext>(DefaultOptions); _userManagerMock = MockHelpers.MockUserManager <ApplicationUser>(); _roleManagerMock = MockHelpers.MockRoleManager <IdentityRole>(); _configurationRoot = new Mock <IConfigurationRoot>(); _identityInitializer = new IdentityInitializer(_dbContextMock.Object, _userManagerMock.Object, _roleManagerMock.Object, _configurationRoot.Object); }
public void InitializerTests() { var initializer = new IdentityInitializer(_validateDatabase, _userManager, _droneRoleValidator); _droneRoleValidator.CreateRoleAsync(Arg.Any <string>()).Returns(true); _droneRoleValidator.ExistRoleAsync(Arg.Any <string>()).Returns(true); _validateDatabase.EnsureCreated().Returns(true); initializer.Initialize(); _userManager.Received().FindByNameAsync(Arg.Any <string>()); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var service = scope.ServiceProvider; var userService = service.GetRequiredService <IUserService>(); var roleService = service.GetRequiredService <IRoleService>(); await IdentityInitializer.InitializeAsync(userService, roleService); host.Run(); } }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var userManager = services.GetRequiredService <UserManager <Consumer> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); IdentityInitializer.SeedData(userManager, roleManager, services.GetRequiredService <IConfiguration>()); } host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var userManager = services.GetRequiredService <UserManager <IdentityBuyer> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await IdentityInitializer.InitializeAsync(userManager, roleManager); } host.Run(); }
private static void InitializeDatabase(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { DbInitializer.EnsurePopulated(services); IdentityInitializer.EnsurePopulated(services).Wait(); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "Databasen kunde inte fyllas."); } } }
private async Task InitializeDB(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetRequiredService <EFDbContext>(); if (!(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists()) { context.Database.EnsureCreated(); } var service = serviceScope.ServiceProvider; var userService = service.GetRequiredService <IUserService>(); var roleService = service.GetRequiredService <IRoleService>(); await IdentityInitializer.InitializeAsync(userService, roleService); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure( IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, ApplicationDbContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); app.UseAuthentication(); app.UseStaticFiles(); #region [ CORS ] app.UseCors("AllowAll"); #endregion #region Swagger app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1"); c.RoutePrefix = string.Empty; }); #endregion // Criação de estruturas, usuários e permissões // na base do ASP.NET Identity Core (caso ainda não // existam) _ = new IdentityInitializer(context, userManager, roleManager) .Initialize(); }
public static void Main(string[] args) { var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); try { config = new ConfigurationBuilder() .AddInMemoryCollection(defaults) .AddEnvironmentVariables("ASPNETCORE_") .AddCommandLine(args) .Build(); var host = BuildWebHost(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { logger.Info(config.ToString()); var dbContext = services.GetService <ApplicationDbContext>(); dbContext.Database.Migrate(); // Seed Roles and Admin User var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); IdentityInitializer.SeedData(userManager, roleManager, dbContext); } catch (Exception ex) { logger.Error(ex, "An error occurred validating DB creation."); } } host.Run(); } catch (Exception ex) { logger.Error(ex, "Stopped program because of exception"); throw; } finally { LogManager.Shutdown(); } }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var serviceScope = host.Services.CreateScope()) { //EasyShopContext var dbContext = serviceScope.ServiceProvider.GetRequiredService <EasyShopContext>(); await dbContext.Database.MigrateAsync(); //RustShopMultiTenantStoreContext var rustShopMultiTenantStoreContext = serviceScope.ServiceProvider.GetRequiredService <RustShopMultiTenantStoreContext>(); await rustShopMultiTenantStoreContext.Database.MigrateAsync(); //Services var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <AppUser> >(); var rustTestStatsInit = serviceScope.ServiceProvider.GetRequiredService <IRustTestStatsData>(); var configuration = serviceScope.ServiceProvider.GetRequiredService <IConfiguration>(); var payPalSettings = serviceScope.ServiceProvider.GetRequiredService <PayPalSettings>(); //Default Identity initialization var basicIdentityInitializer = new IdentityInitializer(dbContext, roleManager, userManager, configuration, payPalSettings); await basicIdentityInitializer.InitializeIdentity(); //Default Rust data initialization var rustDataInit = new RustDefaultDataInitialization(dbContext); await rustDataInit.Initialize(); //RustTestStats initialization await rustTestStatsInit.InitializeDefaultStatsData(); var contactUsDataInit = new ContactUsDataInitializer(dbContext); await contactUsDataInit.Initialize(); await dbContext.SaveChangesAsync(); } await host.RunAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <AppUser> userManager, RoleManager <AppRole> roleManager, IBlogService blogService, ICategoryService categoryService, ICategoryBlogService categoryBlogService) { 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.UseStatusCodePagesWithReExecute("/Home/StatusCode", "?code={0}"); app.UseHttpsRedirection(); app.UseRouting(); app.UseStaticFiles(); var locOptions = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >(); app.UseRequestLocalization(locOptions.Value); app.UseAuthentication(); app.UseAuthorization(); IdentityInitializer.SeedData(userManager, roleManager).Wait(); BlogInitializer.SeedData(blogService, categoryService, categoryBlogService).Wait(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "areas", pattern: "{area}/{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute( name: "default", pattern: "{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, ApplicationDbContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } IdentityInitializer.Initialize(context, userManager, roleManager); app.UseAuthentication(); app.UseHttpsRedirection(); 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, ApplicationDbContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } IdentityInitializer.SeedData(userManager, roleManager); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, DbInitializer seeder, IdentityInitializer identitySeeder) { var options = new DefaultFilesOptions(); options.DefaultFileNames.Clear(); options.DefaultFileNames.Add("index.html"); app.UseDeveloperExceptionPage() .UseCors(builder => builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()) .Use(async(context, next) => { await next(); if (context.Request.Path.Equals("/admin")) { context.Request.Path = "/admin.html"; await next(); } }) .UseSwagger() // Enable middleware to serve generated Swagger as a JSON endpoint. .UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }) // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint. .UseMiddleware(typeof(ErrorWrappingMiddleware)) .UseMvc() .UseDefaultFiles(options) .UseStaticFiles(); seeder.Seed().Wait(); if (env.IsDevelopment()) { identitySeeder.Seed().Wait(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <AppUser> userManager, RoleManager <IdentityRole> roleManager) { 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.UseSession(); IdentityInitializer.CreateAdmin(userManager, roleManager); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); /*app.UseMvc(routes => * { * routes * .MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}") * .MapRoute(name: "api", template: "api/{controller}/{action}/{id?}"); * });*/ app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "areas", pattern: "{area}/{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute( name: "default", pattern: "{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 <User> userManager, RoleManager <Role> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // Initialize minimum configs for database (roles, SuperAdmin user, etc ... ) case not exists IdentityInitializer.SeedData(userManager, roleManager, AdminEmail, AdminPassword); app.ConfigureCustomExceptionMiddleware(); //app.UseHttpsRedirection(); app.UseAuthentication(); app.UseCors(c => c.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials()); app.UseMvc(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IdentityInitializer identityInitializer) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } // Do the initializer identityInitializer.Seed().Wait(); app.UseCookiePolicy(); app.UseHttpsRedirection(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public static void Main(string[] args) { //CreateHostBuilder(args).Build().Run(); var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { var userManager = serviceProvider.GetRequiredService <UserManager <IdentityUser> >(); var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); IdentityInitializer.Seed(userManager, roleManager); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } host.Run(); }