use the browsers debug tools to see the full url and network response. also if CORS, there should of been a message in the browser console.
CORS Latest Release .NET
I have created a new web api project using the latest .net release(.net 8) and I am getting the following error in my angular project.
Http failure response for "url": 0 Unknown Error
see my program.cs below:
var builder = WebApplication.CreateBuilder(args);
var Origin = "Origin";
var AllowedOrigins = builder?.Configuration?.GetValue<string>("AllowedOrigins")?.Split(',');
if (AllowedOrigins != default)
{
builder.Services.AddCors(options => { options.AddPolicy(Origin, policy =>
{
policy.WithOrigins(AllowedOrigins)
.AllowAnyHeader()
.AllowAnyMethod();
});
}); }
builder.Services.Configure<ConfigurationSetting>(builder.Configuration.GetSection("ConfigurationSetting"));
builder.Services.AddScoped<IMyObject, MyObject>();
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder?.Services.AddEndpointsApiExplorer();
builder?.Services.AddSwaggerGen();
builder?.Services.AddControllers();
var app = builder?.Build();
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(Origin);
app.UseStaticFiles();
app.UseAuthorization();
app.MapControllers();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) { app.UseSwagger();
app.UseSwaggerUI(); }
app.Run();