コード例 #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
                              , 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);
        }
コード例 #2
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,
                              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();
        }
コード例 #3
0
        // 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?}"
                    );
            });
        }
コード例 #4
0
        // 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?}");
            });
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: MohdAlQaisi/Assignment
        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();
            });
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
            });
        }
コード例 #8
0
ファイル: Startup.cs プロジェクト: EmreErdogann/WorkFollow
        // 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?}");
            });
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: DenKenobi7/WeatherIn-proj
        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();
        }
コード例 #10
0
        public AccountController(UserManager <IdentityUser> userMgr, SignInManager <IdentityUser> signInMgr)
        {
            (userManager, signInManager) = (userMgr, signInMgr);

            // БД Identity будет заполняться каждый раз, когда создается
            // объект AccountController для обработки НТТР-запроса
            IdentityInitializer.Initialize(userMgr).Wait();
        }
コード例 #11
0
ファイル: Startup.cs プロジェクト: KuuuPER/ParentsProject
 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());
        }
コード例 #13
0
 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>());
        }
コード例 #15
0
        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();
            }
        }
コード例 #16
0
        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();
        }
コード例 #17
0
        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();
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: Danielel/MiljoBrott
 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.");
         }
     }
 }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        // 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();
        }
コード例 #21
0
        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();
            }
        }
コード例 #22
0
        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();
        }
コード例 #23
0
ファイル: Startup.cs プロジェクト: Arifdamar/BlogProject
        // 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?}");
            });
        }
コード例 #24
0
 // 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();
 }
コード例 #25
0
        // 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();
            });
        }
コード例 #26
0
        // 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();
            }
        }
コード例 #27
0
        // 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?}");
            });
        }
コード例 #28
0
        // 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();
        }
コード例 #29
0
ファイル: Startup.cs プロジェクト: prmcrs/random-user-api
        // 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?}");
            });
        }
コード例 #30
0
        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();
        }