public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context, RoleManager <StoreRole> roleManager, UserManager <SneakerSeekerUser> userManager) { StripeConfiguration.SetApiKey(Configuration["Stripe:TestSecretKey"]); 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?}"); }); SeedRoles.CreateRoles(context, userManager, roleManager).Wait(); }
public static void Main(string[] args) { // Create the WebHost object var host = CreateHostBuilder(args).Build(); // Invoke the SeedRoles.CreateRoles() here using (var scope = host.Services.CreateScope()) { // Get the ServiceProvider var services = scope.ServiceProvider; try { // Bind the ServiceProvider and the Configuration(appsetting.json) var serviceProvider = services.GetRequiredService <IServiceProvider>(); var configuration = services.GetRequiredService <IConfiguration>(); // Pass the ServiceProvider and the Configuration object to CreateRoles() SeedRoles.CreateRoles(serviceProvider, configuration).Wait(); } catch (Exception exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exception, "Error - Creating Roles"); } } // Start the Web Application host.Run(); }
public async Task OnGetAsync(string returnUrl = null) { await SeedRoles.GenerateRoles(_userManager, _roleManager); ReturnUrl = returnUrl; ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); }
public static void Main(string[] args) { // create the WebHost object var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { // get the service providers var services = scope.ServiceProvider; try { var serviceProvider = services.GetRequiredService <IServiceProvider>(); // get the Config object for the appsettings.json file var configuration = services.GetRequiredService <IConfiguration>(); // pass the service proiders and the config object to CreateRoles() SeedRoles.CreateRoles(serviceProvider, configuration).Wait(); } catch (Exception exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exception, "An error occurred while creating roles"); } } // start the web app host.Run(); }
public static void Main(string[] args) { IWebHost host = BuildWebHost(args); using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; UserManager <ApplicationUser> userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); try { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task rolesTask = SeedRoles.Initialize(services, userManager); Task productsTask = SeedProducts.Initialize(services); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed // Spinlock until seeding is complete (there is surely a better way to do this?) while (!rolesTask.IsCompleted || !productsTask.IsCompleted) { } } catch { Console.Error.WriteLine( "Could not seed database with admin user and roles."); throw; } } host.Run(); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMiddleware <ErrorHandling>(); app.UseHttpsRedirection(); app.UseCors("AllowSpecificOriginPolicy"); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSwagger(); app.UseSwaggerUI(s => s.SwaggerEndpoint("/swagger/v1/swagger.json", "RESApiService")); using var scope = app.ApplicationServices.CreateScope(); var context = scope.ServiceProvider.GetRequiredService <AppDbContext>(); context.Database.Migrate(); var userManager = scope.ServiceProvider.GetRequiredService <UserManager <User> >(); var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); SeedRoles.SeedAdminRole(roleManager); SeedUsers.SeedAdminUser(userManager); }
// 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) { 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(); SeedRoles.Seed(roleManager); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Participantes}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
// 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) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } SeedRoles.Seed(serviceProvider); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "areas", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
//Use this method to configure the HTTP request pipeline. // 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, RoleManager <UserRole> roleManager, 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(); SeedRoles.Seed(context, roleManager, userManager).Wait(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", //sets the page the webapp opens up to first when starting up pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { try { //var userManager = services.GetRequiredService<UserManager<IdentityUser>>(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); SeedRoles.Initialize(services, roleManager); } catch (Exception ex) { Debug.WriteLine(ex.Message); } var context = services.GetRequiredService <ApplicationDbContext>(); // context.Database.Migrate(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); SeedRoles.EnsureCreated(); SeedAdmin.EnsureCreated(); CreateStorgeDirectory.EnsureCreated(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { 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(); } using var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope(); SeedRoles.Run(serviceScope.ServiceProvider); SeedAdmin.Run(serviceScope.ServiceProvider); app.UseCors(options => options .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() ); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapAreaControllerRoute( "Admin", "Admin", "Admin/{controller=Admin}/{action=Index}/{id?}"); endpoints.MapAreaControllerRoute( "ONG", "ONG", "ONG/{controller=ONG}/{action=Index}/{id?}"); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <AdsContext>(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); SeedRoles.SeedAsync(context).Wait(); SeedAdminUser.SeedAsync(context, userManager).Wait(); } 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, SeedRoles seeder) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } //app.UseHttpsRedirection(); //seeder.Seed(); //use when new roles are to be added app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); app.UseAuthentication(); app.UseMvc(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); SeedRoles.SeedData(roleManager); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } host.Run(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { SeedRoles.CreateUserRoles(services).Wait(); } catch (Exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError("An error occured during migrations."); } } 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, IServiceProvider serviceProvider) { 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(); DatabaseInitializer.Seed(app); app.UseSession(); app.UseAuthentication(); app.UseAuthorization(); SeedRoles.CreateRoles(serviceProvider, Configuration).Wait(); //app.UseEndpoints(endpoints => //{ // endpoints.MapRazorPages(); //}); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var serviceProvider = services.GetRequiredService <IServiceProvider>(); SeedRoles.CreateRoles(serviceProvider).Wait(); } catch (Exception exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exception, "Unable to create and asign new roles."); } } 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, IServiceProvider serviceProvider) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); DbInitializer.Seed(app); app.UseSession(); app.UseAuthentication(); app.UseMvcWithDefaultRoute(); SeedRoles.CreateRoles(serviceProvider, Configuration).Wait(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var serviceProvider = services.GetRequiredService <IServiceProvider>(); var configuration = services.GetRequiredService <IConfiguration>(); SeedRoles.CreateRoles(serviceProvider, configuration).Wait(); } catch (Exception exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exception, "An error occurred while creating roles"); } } host.Run(); }
public static async Task InitializeAsync(ApiContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager, IServiceProvider serviceProvider) { Assembly dalAssembly = null; var assemblies = AppDomain.CurrentDomain.GetAssemblies(); //Loops through all the found assemblies and stores the NET.UNICA.EDU.DAL assembly foreach (var assembly in assemblies) { var assemblyName = assembly.GetName(); if (assemblyName.Name == "DAL") { dalAssembly = assembly; break; } } //Checks if the global assembly exists if (dalAssembly == null) { var exception = new ApplicationException($"Assembly not found"); throw exception; } //Declares the dictionaries to store the types of the NET.UNICA.EDU.DAL.Models and NET.UNICA.EDU.DAL.Seeds namespaces and gets all the types from the global assembly Dictionary <string, Type> modelsTypes = new Dictionary <string, Type>(); Dictionary <string, Type> seedsTypes = new Dictionary <string, Type>(); var dalAssemblyTypes = dalAssembly.GetTypes(); //Loops through all the assembly types and stores the type if the namespace is either NET.UNICA.EDU.DAL.Models or NET.UNICA.EDU.DAL.Seeds foreach (Type dalAssemblyType in dalAssemblyTypes) { if ( dalAssemblyType.IsDefined(typeof(CompilerGeneratedAttribute), false) || dalAssemblyType.Namespace == null || dalAssemblyType.Name == "<>c" ) { continue; } if (dalAssemblyType.Namespace == "DAL.Models") { modelsTypes.Add(dalAssemblyType.Name, dalAssemblyType); } else if (dalAssemblyType.Namespace == "DAL.Seeds") { seedsTypes.Add(dalAssemblyType.Name, dalAssemblyType); } } context.Database.EnsureCreated(); /* if (!context.Users.Any()) * { * context.Users.AddRange(ApplicationUserSeed.Seed(context,userManager)); * context.SaveChanges(); * } * * * * var Password = "******"; * foreach(var user in context.Users) * { * // var identityResult = await userManager.CreateAsync(user); * // await userManager.AddPasswordAsync(user, Password); * * user.PasswordHash = userManager.PasswordHasher.HashPassword(user, "Lusho"); * } * context.SaveChanges(); * context.SaveChanges();*/ var users = ApplicationUserSeed.Seed(); foreach (var user in users) { var identityResult = await userManager.CreateAsync(user, "Lusho"); /* * if (identityResult.Succeeded) * { * * identityResult = await userManager.AddPasswordAsync(user, "Lusho"); * }*/ } context.SaveChanges(); if (!context.Roles.Any()) { context.Roles.AddRange(ApplicationRoleSeed.Seed()); context.SaveChanges(); } SeedRoles newSeed = new SeedRoles(roleManager); if (!context.UserRoles.Any()) { context.UserRoles.AddRange(ApplicationUserRoleSeed.Seed(context)); context.SaveChanges(); } /* * var RoleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>(); * string[] roleNames = { "Admin", "Member" }; * IdentityResult roleResult; * foreach(var roleName in roleNames) * { * var roleExist = await RoleManager.RoleExistsAsync(roleName); * if (!roleExist) * { * roleResult = await RoleManager.CreateAsync(new IdentityRole(roleName)); * } * }*/ }