This is my code
And my api is working just fine
But the CORS is not working
using DatingApp.Data;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddCors(options =>
{
options.AddPolicy(name: "AllowSpecificOrigins",
policy =>
{
policy.WithOrigins("http://localhost:4200").AllowAnyHeader().AllowAnyMethod().AllowCredentials();
});
});
builder.Services.AddDbContext<DataContext>(opt =>
{
opt.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnectionString"));
});
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseRouting();
app.UseCors("AllowSpecificOrigins"); // Use the named CORS policy
app.UseAuthorization();
app.MapControllers();
app.Run();
enter image description here
enter image description here
enter image description here
I have looked everywhere ,, i am not able to figure out what is wrong with this code
It was expected that , with CORS configured , My angular frontend would be able to access the backend
But there is an error somewhere