Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Access to XMLHttpRequest at https://xxx from origin http://yyy has been blocked by CORS policy

03.02.2023 (👁5006)


 

 

Fehlermeldung im Browser Developer Mode

Access to XMLHttpRequest at https://xxx from origin http://yyy has been blocked by CORS policy:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

API Angular Error:

Ein Bild, das Text enthält.

Automatisch generierte Beschreibung

 

Dann muss man in der Web-API mit CORS den Filter zum Frontend.UI freischalten

Ein Bild, das Text, Monitor, Screenshot, drinnen enthält.

Automatisch generierte Beschreibung

Program.cs .NET6 .net7

#region //==< Builder >==

//==< Builder >==

var builder = WebApplication.CreateBuilder(args);

 

// Add services to the container.

 

builder.Services.AddControllers();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen();

 

//*CORS

//< CORS >

//*allow calls from AngularUI

builder.Services.AddCors(options=>options.AddPolicy(name:"FrontendUI",

    policy =>

    {

        policy.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader();

    }

    ));

//</ CORS >

//==</ Builder >==

#endregion //==< Builder >==

 

#region //==< APP >==

//==< APP >==

var app = builder.Build();

 

// Configure the HTTP request pipeline.

if (app.Environment.IsDevelopment())

{

    app.UseSwagger();

    app.UseSwaggerUI();

}

 

//< CORS >

app.UseCors("FrontendUI");

//</ CORS >

 

 

app.UseHttpsRedirection();

 

app.UseAuthorization();

 

app.MapControllers();

 

app.Run();

//==</ APP >==

#endregion //==</ APP >==