Updat for CORS Resolution
This commit is contained in:
parent
d0650c36f3
commit
43eb29c2e8
@ -8,10 +8,16 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
|
|
||||||
// Add services to the container.
|
// 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();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
//builder.Services.AddSwaggerGen();
|
//builder.Services.AddSwaggerGen();
|
||||||
|
// Add Swagger/OpenAPI documentation support.
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
// Include XML comments from your assembly
|
// Include XML comments from your assembly
|
||||||
@ -28,7 +34,6 @@ builder.Services.AddDbContext<AnswerDbContext>(option =>
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
@ -36,8 +41,11 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseAuthorization();
|
|
||||||
|
|
||||||
|
// Enable CORS, authentication, and authorization middleware.
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
|
app.UseAuthorization();
|
||||||
|
// Map controllers to their respective routes.
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
@ -8,12 +8,18 @@ using System.Reflection;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// CORS setup to allow requests from any origin.
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
//builder.Services.AddSwaggerGen();
|
//builder.Services.AddSwaggerGen();
|
||||||
|
// Add Swagger/OpenAPI documentation support.
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
// Include XML comments from your assembly
|
// Include XML comments from your assembly
|
||||||
@ -45,6 +51,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable CORS, authentication, and authorization middleware.
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
@ -6,6 +6,11 @@ using System.Reflection;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// CORS setup to allow requests from any origin.
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
@ -36,6 +41,9 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Enable CORS, authentication, and authorization middleware.
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
@ -6,12 +6,18 @@ using System.Reflection;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
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();
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
//builder.Services.AddSwaggerGen();
|
// Add Swagger/OpenAPI documentation support.
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
// Include XML comments from your assembly
|
// Include XML comments from your assembly
|
||||||
@ -43,6 +49,9 @@ if (app.Environment.IsDevelopment())
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable CORS, authentication, and authorization middleware.
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
@ -5,13 +5,18 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
// CORS setup to allow requests from any origin.
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
// Add controller services and API Explorer for endpoint discovery.
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
//builder.Services.AddSwaggerGen();
|
// Add Swagger/OpenAPI documentation support.
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
// Include XML comments from your assembly
|
// Include XML comments from your assembly
|
||||||
@ -44,6 +49,9 @@ if (app.Environment.IsDevelopment())
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable CORS, authentication, and authorization middleware.
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
@ -15,8 +15,14 @@ builder.Services.AddControllers();
|
|||||||
builder.Services.AddScoped<IQuestionsProvider, QuestionsProvider>();
|
builder.Services.AddScoped<IQuestionsProvider, QuestionsProvider>();
|
||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
|
|
||||||
|
// CORS setup to allow requests from any origin.
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Add controller services and API Explorer for endpoint discovery.
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
//builder.Services.AddSwaggerGen();
|
// Add Swagger/OpenAPI documentation support.
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
// Include XML comments from your assembly
|
// Include XML comments from your assembly
|
||||||
@ -44,6 +50,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable CORS, authentication, and authorization middleware.
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
@ -16,6 +16,10 @@ const int intervalForCircuitBraker = 5; //5 seconds
|
|||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
// CORS setup to allow requests from any origin.
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
|
||||||
builder.Services.AddScoped<ISurveysResponse, SurveyResponsesProvider>();
|
builder.Services.AddScoped<ISurveysResponse, SurveyResponsesProvider>();
|
||||||
@ -36,6 +40,7 @@ builder.Services.AddHttpClient<IHttpUtil, HttpUtil>().
|
|||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
//builder.Services.AddSwaggerGen();
|
//builder.Services.AddSwaggerGen();
|
||||||
|
// Add Swagger/OpenAPI documentation support.
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
// Include XML comments from your assembly
|
// Include XML comments from your assembly
|
||||||
@ -56,6 +61,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable CORS, authentication, and authorization middleware.
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
@ -10,7 +10,11 @@ using System.Reflection;
|
|||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
|
// Retrieve the security key for JWT token validation.
|
||||||
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey");
|
||||||
|
|
||||||
|
// Configure JWT authentication and validation.
|
||||||
builder.Services.AddAuthentication(item =>
|
builder.Services.AddAuthentication(item =>
|
||||||
{
|
{
|
||||||
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
@ -29,12 +33,18 @@ builder.Services.AddAuthentication(item =>
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// CORS setup to allow requests from any origin.
|
||||||
|
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
|
||||||
|
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
// Add controller services and API Explorer for endpoint discovery.
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddScoped<ISurveyProvider, SurveysProvider>();
|
builder.Services.AddScoped<ISurveyProvider, SurveysProvider>();
|
||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
//builder.Services.AddSwaggerGen();
|
|
||||||
|
// Add Swagger/OpenAPI documentation support.
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
// Include XML comments from your assembly
|
// Include XML comments from your assembly
|
||||||
@ -42,10 +52,13 @@ builder.Services.AddSwaggerGen(c =>
|
|||||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||||
c.IncludeXmlComments(xmlPath);
|
c.IncludeXmlComments(xmlPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Configure the database context for SurveysDbContext using SQL Server.
|
||||||
builder.Services.AddDbContext<SurveysDbContext>(option =>
|
builder.Services.AddDbContext<SurveysDbContext>(option =>
|
||||||
{
|
{
|
||||||
option.UseSqlServer("SurveyConnection");
|
option.UseSqlServer("SurveyConnection");
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
@ -53,7 +66,7 @@ if (app.Environment.IsDevelopment())
|
|||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
|
// Seed initial data in the database when in development mode
|
||||||
using (var serviceScope = app.Services.CreateScope())
|
using (var serviceScope = app.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var services = serviceScope.ServiceProvider;
|
var services = serviceScope.ServiceProvider;
|
||||||
@ -61,10 +74,11 @@ if (app.Environment.IsDevelopment())
|
|||||||
surveyProvider.seedData();
|
surveyProvider.seedData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Enable CORS, authentication, and authorization middleware.
|
||||||
|
app.UseCors("DamageAppCorsPolicy");
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
// Map controllers to their respective routes.
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
Loading…
Reference in New Issue
Block a user