I've already enabled CORS on the project in C# .net Core
In startup.cs
I've added lines
...
services.AddCors();
...
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
But when I try to use API in another Blazor
project I see in logs in my API project on Host this error
The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time. Configure the policy by listing individual origins if credentials needs to be supported
My code in Blazor
using (HttpClient http = new HttpClient()) {
http.DefaultRequestHeaders.Add("Authorization", "Token");
var response = await http.GetStringAsync("https://example.com?prm=2");
Console.WriteLine(response);
dynamicContent = response;
}
Before I enable Cors I see another error in the browser console
What can I change for solving it?
*
for the origin when using credentials. Set the origin to your server's actual domain name. Also, these headers must be set by the server, not in your client headers.http.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
and in rowvar response = await Http.GetStringAsync("https://example.com?prm=2");
changeHttp
tohttp