1 | using Microsoft.AspNetCore.Identity;
|
---|
2 | using Models.DatabaseModels;
|
---|
3 | using Microsoft.EntityFrameworkCore;
|
---|
4 | using Microsoft.AspNetCore.Authentication.Cookies;
|
---|
5 | using Dal.ApplicationStorage;
|
---|
6 | using Microsoft.Extensions.DependencyInjection.Extensions;
|
---|
7 | using Dal.ApplicationStorage.DataAccess.Abstract;
|
---|
8 | using Dal.ApplicationStorage.DataAccess.Concrete;
|
---|
9 | using Microsoft.AspNetCore.Mvc;
|
---|
10 | using Microsoft.Extensions.Options;
|
---|
11 |
|
---|
12 | var builder = WebApplication.CreateBuilder(args);
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 | // Add services to the container.
|
---|
17 | builder.Services.AddControllersWithViews(opt => opt.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()));
|
---|
18 |
|
---|
19 | // Data Access scoped
|
---|
20 | builder.Services.TryAddScoped<IIdentityCustomDa, IdentityDa>();
|
---|
21 | builder.Services.TryAddScoped<ISearchDa, SearchDa>();
|
---|
22 | builder.Services.TryAddScoped<ICompanyDa, CompanyDa>();
|
---|
23 | builder.Services.TryAddScoped<IAdministrator, AdministratorDa>();
|
---|
24 |
|
---|
25 |
|
---|
26 | builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
---|
27 | builder.Services.AddSession();
|
---|
28 | builder.Services.AddSession(options => {
|
---|
29 | options.IdleTimeout = TimeSpan.FromMinutes(30);
|
---|
30 | });
|
---|
31 |
|
---|
32 | builder.Services.AddEntityFrameworkNpgsql().AddDbContext<ApiContext>();
|
---|
33 |
|
---|
34 | builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
---|
35 | .AddCookie(options =>
|
---|
36 | {
|
---|
37 | options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
|
---|
38 | options.SlidingExpiration = true;
|
---|
39 | options.AccessDeniedPath = "/Forbidden/";
|
---|
40 | });
|
---|
41 |
|
---|
42 |
|
---|
43 | var app = builder.Build();
|
---|
44 |
|
---|
45 | // Configure the HTTP request pipeline.
|
---|
46 | if (!app.Environment.IsDevelopment())
|
---|
47 | {
|
---|
48 | app.UseExceptionHandler("/Home/Error");
|
---|
49 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
---|
50 | app.UseHsts();
|
---|
51 | }
|
---|
52 |
|
---|
53 | app.UseCookiePolicy();
|
---|
54 | app.UseHttpsRedirection();
|
---|
55 | app.UseStaticFiles();
|
---|
56 | app.UseSession();
|
---|
57 |
|
---|
58 | app.UseRouting();
|
---|
59 | app.UseAuthentication();
|
---|
60 |
|
---|
61 | app.UseAuthorization();
|
---|
62 |
|
---|
63 | app.MapControllerRoute(
|
---|
64 | name: "default",
|
---|
65 | pattern: "{controller=Home}/{action=Index}/{id?}");
|
---|
66 |
|
---|
67 | app.Run();
|
---|