| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using Microsoft.AspNetCore.Identity;
- using Microsoft.EntityFrameworkCore;
- using VolgaIT.Data;
- var builder = WebApplication.CreateBuilder(args);
- var connectionString = builder.Configuration.GetConnectionString("ConnectionString");
- // Add services to the container.
- builder.Services.AddControllersWithViews();
- builder.Services.AddDbContext<DataContext>(opt =>
- {
- opt.UseNpgsql(connectionString);
- });
- builder.Services.AddIdentity<IdentityUser, IdentityRole>(opt=>
- {
- opt.User.RequireUniqueEmail = true;
- opt.Password.RequireDigit = false;
- opt.Password.RequiredLength = 3;
- opt.Password.RequireUppercase = false;
- opt.Password.RequireNonAlphanumeric = false;
- opt.Password.RequireLowercase = false;
- }).AddEntityFrameworkStores<DataContext>().AddTokenProvider<DataProtectorTokenProvider<IdentityUser>>(TokenOptions.DefaultProvider);
- builder.Services.AddScoped<DataContext>();
- var app = builder.Build();
- // Configure the HTTP request pipeline.
- if (!app.Environment.IsDevelopment())
- {
- app.UseExceptionHandler("/Home/Error");
- app.UseHsts();
- }
- app.UseHttpsRedirection();
- app.UseStaticFiles();
- app.UseRouting();
- app.UseAuthentication();
- app.UseAuthorization();
- app.MapControllerRoute(
- name: "default",
- pattern: "{controller=Home}/{action=Index}/{id?}");
- using (var scope = app.Services.CreateScope())
- {
- var roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole>>();
- var context = scope.ServiceProvider.GetRequiredService<DataContext>();
- await DataBaseInit.InitDataBase(roleManager, context);
- }
- app.Run();
|