Updat for CORS Resolution

This commit is contained in:
Santhosh S
2023-11-10 14:09:43 -05:00
parent d0650c36f3
commit 43eb29c2e8
8 changed files with 81 additions and 11 deletions

View File

@ -8,10 +8,16 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// CORS setup to allow requests from any origin.
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
//builder.Services.AddSwaggerGen();
// Add Swagger/OpenAPI documentation support.
builder.Services.AddSwaggerGen(c =>
{
// Include XML comments from your assembly
@ -28,7 +34,6 @@ builder.Services.AddDbContext<AnswerDbContext>(option =>
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
@ -36,8 +41,11 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUI();
}
app.UseAuthorization();
// Enable CORS, authentication, and authorization middleware.
app.UseCors("DamageAppCorsPolicy");
app.UseAuthorization();
// Map controllers to their respective routes.
app.MapControllers();
app.Run();