using Microsoft.AspNetCore.Identity; using Models.DatabaseModels; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Authentication.Cookies; using Dal.ApplicationStorage; using Microsoft.Extensions.DependencyInjection.Extensions; using Dal.ApplicationStorage.DataAccess.Abstract; using Dal.ApplicationStorage.DataAccess.Concrete; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(opt => opt.Filters.Add(new AutoValidateAntiforgeryTokenAttribute())); // Data Access scoped builder.Services.TryAddScoped(); builder.Services.TryAddScoped(); builder.Services.TryAddScoped(); builder.Services.TryAddScoped(); builder.Services.AddSingleton(); builder.Services.AddSession(); builder.Services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(30); }); builder.Services.AddEntityFrameworkNpgsql().AddDbContext(); builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.ExpireTimeSpan = TimeSpan.FromMinutes(20); options.SlidingExpiration = true; options.AccessDeniedPath = "/Forbidden/"; }); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { 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.UseCookiePolicy(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSession(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run();