Aggiunta policy CORS richiesta in README
This commit is contained in:
17
README.md
17
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)
|
||||
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();
|
||||
});
|
||||
});
|
||||
```
|
||||
Reference in New Issue
Block a user