// 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(); } //app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseHangfireDashboard(); HangFireJobScheduler.Configure(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{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, ApplicationDbContext context, UserManager <IdentityUser> userManager, IHostingEnvironment env, RoleManager <IdentityRole> roleManager) { 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.UseHangfireDashboard(); app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 1 }); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); HangFireJobScheduler.ScheduleRecurringJobs(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); //Seed Default Users DefaultUsers.DefaultUsers.CreateDefaultUsers(context, userManager, roleManager).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseMigrationsEndPoint(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangFireAuthorizationFilter() } }); HangFireJobScheduler.ScheduleRecurringJobs(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); using (IServiceScope scope = app.ApplicationServices.CreateScope()) { RoleManager <IdentityRole> RoleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); UserManager <ApplicationUser> UserManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(); //var JobsRepo = scope.ServiceProvider.GetRequiredService<IJobPostingRepository>(); //await JobsRepo.BuildCache(); ApplicationDbContext content = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); IdentityResult roleResult; //Adding Admin Role bool roleCheck = await RoleManager.RoleExistsAsync("Admin"); if (!roleCheck) { //create the roles and seed them to the database roleResult = await RoleManager.CreateAsync(new IdentityRole("Admin")); } //Assign Admin role to the main User here we have given our newly registered //login id for Admin management // Also Assigning them Claims to perform CRUD operations ApplicationUser user = await UserManager.FindByEmailAsync("*****@*****.**"); if (user != null) { IList <string> currentUserRoles = await UserManager.GetRolesAsync(user); if (!currentUserRoles.Contains("Admin")) { await UserManager.AddToRoleAsync(user, "Admin"); } } } }
public static async Task UseStartUpMethodsAsync(this IApplicationBuilder app) { await Seeder.CreateUserRoles(app); HangFireJobScheduler.ScheduleRecurringJobs(); }