コード例 #1
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?}"
                    );
            });
        }
コード例 #2
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?}");
            });
        }
コード例 #3
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();
        }
コード例 #4
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();
            }
        }
コード例 #5
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?}");
            });
        }
コード例 #6
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();
            });
        }
コード例 #7
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();
        }
コード例 #8
0
ファイル: Startup.cs プロジェクト: PPalac/Info-Flow-API
        // 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 <User> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <DbCtx>();
                context.Database.EnsureCreated();
            }
            app.UseAuthentication();

            IdentityInitializer.SeedData(userManager, roleManager);

            app.UseMvc()
            .UseSwagger()
            .UseSwaggerUI(opt => opt.SwaggerEndpoint("/swagger/v1/swagger.json", "Info Flow API V1.0"));
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: Motorui/MyWayRazor
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <ApplicationRole> >();
                    var context     = services.GetRequiredService <ApplicationDbContext>();
                    IdentityInitializer.SeedData(userManager, roleManager, context);
                    DbInitializer.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: antoinechampion/Bargio
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope()) {
                CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
                var services    = scope.ServiceProvider;
                var userManager = services.GetService <UserManager <IdentityUserDefaultPwd> >();
                var roleManager = services.GetService <RoleManager <IdentityRole> >();
                var context     = services.GetRequiredService <ApplicationDbContext>();
                context.Database.Migrate();

                // requires using Microsoft.Extensions.Configuration;
                var config = host.Services.GetRequiredService <IConfiguration>();
                // Set password with the Secret Manager tool.
                // dotnet user-secrets set SeedUserPW <pw>


                #region Seed DB

                var logger     = services.GetRequiredService <ILogger <Program> >();
                var testUserPw = config["SeedUserPW"];
                try {
                    UserDataInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the UserData DB.");
                }

                try {
                    IdentityInitializer.SeedData(userManager, roleManager).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the Identity DB.");
                }

                try {
                    PromsKeyboardShortcutInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the PromsKeyboardShortcut DB.");
                }

                try {
                    SystemParametersInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the SystemParameters DB.");
                }

                try {
                    ProductsInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the ProductsInitializer DB.");
                }

                try {
                    TransactionHistoryInitializer.SeedData(context).Wait();
                }
                catch (Exception ex) {
                    logger.LogError(ex.Message, "An error occurred seeding the TransactionHistory DB.");
                }

                #endregion
            }

            host.Run();
            CreateWebHostBuilder(args)
            .Build().Run();
        }