Mise en place de la structure définitive du CRUD et modification de la page principale avec les datas
This commit is contained in:
53
Program.cs
53
Program.cs
@@ -1,21 +1,58 @@
|
||||
using administration.Models;
|
||||
using administration.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using static DBConnectionController;
|
||||
|
||||
namespace administration
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
// Charger les variables d'environnement depuis .env
|
||||
DotNetEnv.Env.Load();
|
||||
|
||||
// Add services to the container.
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddDbContext<FinancesContext>(options =>
|
||||
options.UseSqlServer(
|
||||
Environment.GetEnvironmentVariable("ADMIN_DB_CONNECTION"),
|
||||
sqlOptions => sqlOptions.EnableRetryOnFailure()
|
||||
)
|
||||
);
|
||||
|
||||
AppSettings.Initialize(builder.Configuration);
|
||||
|
||||
builder.Services.AddSession(options =>
|
||||
{
|
||||
options.IdleTimeout = TimeSpan.FromMinutes(300); // Durée d'expiration
|
||||
options.Cookie.HttpOnly = true;
|
||||
options.Cookie.IsEssential = true;
|
||||
});
|
||||
|
||||
// Ajouter les services MVC
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
builder.Services.AddHttpContextAccessor(); // obligatoire
|
||||
builder.Services.AddScoped<IUserSessionService, UserSessionService>();
|
||||
|
||||
|
||||
// Configurer la politique CORS pour autoriser l'accès depuis le frontend local
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowFrontend", policy =>
|
||||
{
|
||||
policy.WithOrigins("http://localhost:5018")
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
// Configuration du pipeline HTTP
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -24,12 +61,20 @@ namespace administration
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
// 💡 CORS doit être placé entre UseRouting et UseAuthorization
|
||||
app.UseRouting();
|
||||
|
||||
app.UseCors("AllowFrontend");
|
||||
|
||||
app.UseSession(); // ✅ ici, avant l’authentification
|
||||
app.UseAuthorization();
|
||||
|
||||
// Route par défaut
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user