public void ConfigureServices(IServiceCollection services) { var appSettings = new AppSettings(); Configuration.Bind(appSettings); services.AddSingleton(appSettings); services.AddDbContext <DataContext>(options => options.UseSqlite(DataContext.ConnectionString)); services.AddControllers() .AddNewtonsoftJson(); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "wwwroot"; }); services.AddHttpContextAccessor(); services.AddCors(options => { options.AddPolicy("Dev", builder => { builder.AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin(); }); }); services.AddHttpClient(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.SlidingExpiration = true; }); services.AddAuthorization(); services.AddIdentity <IdentityUser, IdentityRole>(options => { options.User.RequireUniqueEmail = false; options.Password.RequiredLength = 10; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequiredUniqueChars = 5; }) .AddEntityFrameworkStores <DataContext>() .AddDefaultTokenProviders(); services.ConfigureApplicationCookie(options => { options.Events.OnRedirectToLogin = context => { context.Response.StatusCode = StatusCodes.Status401Unauthorized; return(Task.CompletedTask); }; options.Cookie.Name = "SID"; }); DiConfig.Config(services); Service.DiConfig.Config(services); }