Esempio n. 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,
                              ApplicationDbContext ctx,
                              UserManager <User> userManager,
                              RoleManager <IdentityRole> 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();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            IdentityDataSeeder.Initialize(ctx, userManager, roleManager).Wait();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
Esempio n. 2
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 <User> userManager, RoleManager <IdentityRole> roleManager)
        {
            AzureStorageConfiguration.Configure(app.ApplicationServices.GetRequiredService <IConfiguration>());
            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.UseCorsExt();
            app.UseHttpsRedirection();

            app.SetUpStaticFiles(Configuration);
            app.SetUpAzureStorage();
            //app.AddCorsRuleForAzure();

            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.ConfigureAndUseSwagger();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHealthChecks("/health");
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseProxyToSpaDevelopmentServer("http://localhost:4200/");
                    // spa.UseAngularCliServer(npmScript: "start");
                }
            });

            IdentityDataSeeder.SeedData(userManager, roleManager, Configuration);
        }
Esempio n. 3
0
        public UnitOfWork(AppDbContext context, UserManager <User> userManager, RoleManager <IdentityRole> roleManager)
        {
            _disposed   = false;
            _context    = context;
            UserManager = userManager;
            RoleManager = roleManager;

            IdentityDataSeeder.Seed(userManager, roleManager);
        }
Esempio n. 4
0
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     // Create a new scope to retrieve scoped services, as the DbContext class
     // is registered as "scoped"
     using (var scope = _serviceProvider.CreateScope())
     {
         await IdentityDataSeeder <ApplicationUser, IdentityRole> .SeedDataAsync(
             scope.ServiceProvider,
             _logger);
     }
 }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    // Since we want to use scaffolding, we can't use an async Main method so we
                    // just wait for the task to finish in the old fashioned way
                    IdentityDataSeeder <ApplicationUser, IdentityRole> .SeedDataAsync(services).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }