// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// <summary> /// The Configure /// </summary> /// <param name="app">The app<see cref="IApplicationBuilder"/></param> /// <param name="env">The env<see cref="IHostingEnvironment"/></param> public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); ApplicationDbInitializer.SeedData(userManager, roleManager); } 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.UseHangfireServer(); app.UseHangfireDashboard("/jobs", new DashboardOptions() { DisplayStorageConnectionString = false, // Authorization = new[] { new CustomAuthorizeFilter() }, DashboardTitle = "Scheduled Jobs Overview" }); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(); }
public void Configure( IApplicationBuilder app, IHostingEnvironment env, UserManager <User> userManager, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } 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?}"); }); //Ensure Database Create If It doesn't exists using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); context.Database.EnsureCreated(); ApplicationDbInitializer.SeedData(userManager, roleManager, context); } }
public IActionResult CreateDefaults() { //unitOfWork.MigrateDatabse("Initial"); ApplicationDbInitializer.SeedData(userManager, roleManager, appSettings); bool succseeded = ApplicationDbInitializer.SeedOtherTables(unitOfWork); //ApplicationDbInitializer.SeedData(userManager, roleManager, unitOfWork, appSettings); //var data = new //{ // message = "exampel response", // requestInfo = HttpContext.Request.Headers.ToList() //}; var data = new { message = "error, already exists" }; if (succseeded) { data = new { message = "ok" } } ; return(Ok(new { jwt = data })); }
// 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) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } 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.UseCookiePolicy(); app.UseAuthentication(); ApplicationDbInitializer.SeedData(userManager, roleManager).Wait(); 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) { 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.UseElmah(); app.UseStatusCodePagesWithReExecute("/StatusCode/{0}"); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapAreaControllerRoute( areaName: "Panel", name: "panel", pattern: "/panel/{controller=Home}/{action=Index}/{id?}" ); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); //Database Creation using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>()?.CreateScope()) { if (serviceScope != null) { var roleManager = serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >(); var userManager = serviceScope.ServiceProvider.GetService <UserManager <User> >(); var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); context.Database.EnsureCreated(); var roles = new List <string>() { ConstantUserRoles.SuperAdmin, ConstantUserRoles.Admin, ConstantUserRoles.Writer }; var user = new User() { FirstName = "FirstName", LastName = "LastName", UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, PhoneNumberConfirmed = true, IsActive = true, FilesPathGuid = Guid.NewGuid(), CreateDate = DateTime.Now, LastEditDate = DateTime.Now }; ApplicationDbInitializer.SeedData(context, userManager, roleManager, roles, ConstantUserRoles.SuperAdmin, user, "p@ss123"); } } }