-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (52 loc) · 1.58 KB
/
Copy pathProgram.cs
File metadata and controls
63 lines (52 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Microsoft.EntityFrameworkCore;
using UserManagementApp.Data;
var builder = WebApplication.CreateBuilder(args);
// MVC
builder.Services.AddControllersWithViews();
// DB - PostgreSQL
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
// SESSION - CONFIGURATION COMPLÈTE POUR RENDER
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.Cookie.SameSite = SameSiteMode.Lax;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
options.Cookie.Name = ".UserManagementApp.Session";
});
var app = builder.Build();
// Middleware pipeline
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseMiddleware<AuthMiddleware>();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Auth}/{action=Login}/{id?}");
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
try
{
await dbContext.Database.MigrateAsync();
Console.WriteLine("✅ Database migrations applied");
}
catch (Exception ex)
{
Console.WriteLine($"❌ Migration error: {ex.Message}");
}
}
app.MapGet("/test-login", async context =>
{
context.Response.Redirect("/Auth/LoginNoToken");
});
app.Run();