Bonjour,
J'ai un soucis avec l'ordre des Middleware dans mon application ASP.NET CORE 9. Voici le contenu de mon fichier Programs.cs:
Voici le contenu de Terminal. Apparemment, il est impossible de lire les CORS.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 API.Middleware; using Core.Interfaces; using Infrastructure.Data; using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddDbContext<StoreContext>(options => { options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")); }); builder.Services.AddScoped<IProductRepository, ProductRepository>(); builder.Services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>)); // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi // builder.Services.AddOpenApi(); builder.Services.AddControllers(); var app = builder.Build(); app.UseMiddleware<ExceptionMiddleware>(); app.UseCors(x => x.AllowAnyHeader().AllowAnyHeader() .WithOrigins("http://localhost:4200", "https://localhost:4200")); app.UseCors(); app.MapControllers(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); } try { // using var scope = app.Services.CreateScope(); // var services = scope.ServiceProvider; // var context = services.GetRequiredService<StoreContext>(); // if (!context.Database.CanConnect()) // { Console.WriteLine("Impossible de se connecter à la base de données"); } // await context.Database.MigrateAsync();// Si la Db n'existe pas, elle va la créer // await StoreContextSeed.SeedAsync(context);// Peupler la Db avec des données de test } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } app.Run();
Quelqu'un aurait-il une idée?
Partager