.NET ile hazırladığınız bir API'den react ile veri almaya çalışırken aşağıdaki hatayı alıyorsanız:
"'Access to fetch at '...' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.'"
startup.cs'de ConfigureServices altına;
services.AddCors();
ve Configure'da yer alan app.UseRouting();altına;
app.UseCors(opt =>
{
opt.AllowAnyHeader().AllowAnyMethod()
.WithOrigins("http://localhost:3000");
});
kodlarını yazmanız yeterli olacaktır.
Hiç yorum yok:
Yorum Gönder