From fe1d5edcfe247033a50b9419c36c92fc0c2a2269 Mon Sep 17 00:00:00 2001 From: AndreStork Date: Mon, 10 Nov 2025 12:43:29 +0100 Subject: [PATCH] Aggiunta policy CORS richiesta in README --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c3993c..4fce78c 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,19 @@ Per svariati motivi il web frontend potrebbe non riuscire ad effettuare richiest In caso di errori CORS assicurarsi che: 1. Il protocollo tra server web frontend e server API sia lo stesso (`HTTP` con `HTTP` o `HTTPS` con `HTTPS`, mai `HTTP` con `HTTPS` o viceversa) 2. Nel caso in cui venga usato il protocollo `HTTPS`, il server API deve avere un certificato valido (il certificato autofirmato di ASP.NET non funzionerà) -3. Nel progetto in ASP.NET aggiungere e usare una policy CORS verso l'endpoint del server web del frontend (accettare ogni origin è possibile ma sconsigliabile in production) assicurandosi di accettare ogni header e metodo. [Maggiori informazioni sull'implementazione delle policy CORS in ASP.NET Core](https://learn.microsoft.com/it-it/aspnet/core/security/cors?view=aspnetcore-8.0) \ No newline at end of file +3. Nel progetto in ASP.NET aggiungere e usare una policy CORS verso l'endpoint del server web del frontend (accettare ogni origin è possibile ma sconsigliabile in production) assicurandosi di accettare ogni header e metodo. [Maggiori informazioni sull'implementazione delle policy CORS in ASP.NET Core](https://learn.microsoft.com/it-it/aspnet/core/security/cors?view=aspnetcore-8.0) + +```cs +builder.Services.AddCors(options => + { + options.AddPolicy(name: MyAllowSpecificOrigins, + policy => + { + policy.WithOrigins("http://127.0.0.1:5500", + "http://localhost:5500") + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); + }); + }); +``` \ No newline at end of file