CORS Error, .NET 7 and ReactJS

I fixed this issue by adding this CORS configuration in my ASP.NET app:
And also I have added { withCredential : true } header to client request.
To allow credentials you app need to regiser specific origin, do not use .AllowAnyOrigin() with .AllowCredentials() it goes wrong. If you work with credentials (cookie and etc.) you must use specific origin url!

app.UseCors(builder =>
{
    builder
    .WithOrigins("http://localhost:5173") // my client app url
    .AllowAnyMethod()
    .AllowAnyHeader()
    .AllowCredentials();
});