Changeset fa0fbaf for KernelRecordsMVC.Web/Program.cs
- Timestamp:
- 09/01/26 06:11:34 (4 weeks ago)
- Branches:
- main
- Children:
- d2eccb3
- Parents:
- 08aefc6
- File:
-
- 1 edited
-
KernelRecordsMVC.Web/Program.cs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
KernelRecordsMVC.Web/Program.cs
r08aefc6 rfa0fbaf 1 1 using Microsoft.EntityFrameworkCore; 2 using KernelRecordsMVC.Data; 2 using Npgsql; 3 using Npgsql.NameTranslation; 4 using KernelRecordsMVC.Domain.Enums; 5 using KernelRecordsMVC.Infrastructure.Data; 3 6 4 7 var builder = WebApplication.CreateBuilder(args); 5 8 9 // ========================================== 10 // AUTHENTICATION 11 // ========================================== 12 13 builder.Services 14 .AddAuthentication("Cookies") 15 .AddCookie("Cookies", options => 16 { 17 options.LoginPath = "/Account/Login"; 18 options.AccessDeniedPath = "/Account/Login"; 19 options.ExpireTimeSpan = TimeSpan.FromHours(8); 20 options.SlidingExpiration = true; 21 }); 22 23 builder.Services.AddAuthorization(); 24 6 25 builder.Services.AddControllersWithViews(); 7 26 27 // ========================================== 28 // DATABASE 29 // ========================================== 30 31 var dataSourceBuilder = new NpgsqlDataSourceBuilder( 32 builder.Configuration.GetConnectionString("KernelRecords")); 33 34 var nameTranslator = new NpgsqlNullNameTranslator(); 35 36 dataSourceBuilder.MapEnum<AdminType>( 37 "project.admin_type", 38 nameTranslator); 39 40 dataSourceBuilder.MapEnum<ProductFormat>( 41 "project.product_format", 42 nameTranslator); 43 44 dataSourceBuilder.MapEnum<PaymentMethodType>( 45 "project.payment_method_type", 46 nameTranslator); 47 48 dataSourceBuilder.MapEnum<OrderStatusType>( 49 "project.order_status_type", 50 nameTranslator); 51 52 dataSourceBuilder.MapEnum<ModificationType>( 53 "project.modification_type", 54 nameTranslator); 55 56 dataSourceBuilder.MapEnum<ArtistReleaseType>( 57 "project.artist_release_type", 58 nameTranslator); 59 60 var dataSource = dataSourceBuilder.Build(); 61 8 62 builder.Services.AddDbContext<KernelRecordsContext>(options => 9 options.UseNpgsql( 10 builder.Configuration.GetConnectionString("KernelRecords"))); 63 options.UseNpgsql(dataSource)); 11 64 12 builder.Services.AddSession(); 65 // ========================================== 66 // SESSION 67 // ========================================== 68 69 builder.Services.AddSession(options => 70 { 71 options.IdleTimeout = TimeSpan.FromHours(2); 72 options.Cookie.HttpOnly = true; 73 options.Cookie.IsEssential = true; 74 }); 13 75 14 76 var app = builder.Build(); 77 78 // ========================================== 79 // MIDDLEWARE 80 // ========================================== 15 81 16 82 if (!app.Environment.IsDevelopment()) … … 21 87 22 88 app.UseHttpsRedirection(); 89 23 90 app.UseStaticFiles(); 24 91 … … 26 93 27 94 app.UseSession(); 95 96 app.UseAuthentication(); 28 97 29 98 app.UseAuthorization();
Note:
See TracChangeset
for help on using the changeset viewer.
