The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time.
is thrown when one CORS policy has both AllowAnyOrigin() and
AllowCredentials(). Replace AllowAnyOrigin() with the origins
that really call the API, listed in WithOrigins(...), and keep
AllowCredentials().
In this test the app did not even start: the exception stopped the host before Kestrel
took a single request. With WithOrigins("http://localhost:5173") it started,
and a request from that origin got both CORS headers back.
The error
The server console (stdout, from the host's logger) printed this, and the process exited;
the curl.exe request that followed got no answer at all:
crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
Application startup exception
System.InvalidOperationException: The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time. Configure the CORS policy by listing individual origins if credentials needs to be supported.
at Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder.Build()
at Microsoft.AspNetCore.Cors.Infrastructure.CorsOptions.AddPolicy(String name, Action`1 configurePolicy)
at Program.<>c.<<Main>$>b__0_0(CorsOptions options) in ...\lab\Program.cs:line 5
...
at Microsoft.AspNetCore.Cors.Infrastructure.CorsService..ctor(IOptions`1 options, ILoggerFactory loggerFactory)
...
fail: Microsoft.Extensions.Hosting.Internal.Host[11]
Hosting failed to start
...
The long scratch path before \lab\Program.cs is shortened; nothing else in
the shown lines is changed.
Why it happens
The policy that produced it:
...
builder.Services.AddCors(options =>
{
options.AddPolicy("Frontend", policy => policy
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowCredentials());
});
...
app.UseCors("Frontend");
...
The message states the rule: a policy may allow any origin, or allow credentials
(cookies and other browser-managed credentials), but not both. ASP.NET Core refuses to
build a policy that asks for both, and the stack trace shows where: CorsPolicyBuilder.Build(),
called from AddPolicy, reached while UseCors created its
middleware during startup. The Program.cs:line 5 in the trace points at the
AddCors lambda.
The fix
...
builder.Services.AddCors(options =>
{
options.AddPolicy("Frontend", policy => policy
.WithOrigins("http://localhost:5173")
.AllowAnyHeader()
.AllowCredentials());
});
...
The app started, and a request carrying that origin got it echoed back with the credentials header:
PS> curl.exe -s -i -H "Origin: http://localhost:5173" http://127.0.0.1:15630/patients
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Sat, 14 Nov 2026 01:16:02 GMT
Server: Kestrel
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:5173
Transfer-Encoding: chunked
["Maria Garcia","David Chen"]
Put every front-end origin in WithOrigins, with scheme and port, as the
browser sends it. If the API needs no cookies or browser-managed credentials, the other
way out is to keep AllowAnyOrigin() and drop AllowCredentials().
That was tested too: the app started, and the same request got the wildcard back with no
credentials header:
PS> curl.exe -s -i -H "Origin: http://localhost:5173" http://127.0.0.1:15630/patients
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Sat, 14 Nov 2026 01:28:32 GMT
Server: Kestrel
Access-Control-Allow-Origin: *
Transfer-Encoding: chunked
["Maria Garcia","David Chen"]
How it was reproduced
A minimal API made with dotnet new web -f net10.0 on SDK 11.0.100, running on
Microsoft.AspNetCore.App 10.0.15 in the Development environment, built and started by a small script, start.ps1, which runs dotnet build -nologo -v q in the project folder and then bin\Debug\net10.0\FixLab.exe --urls http://127.0.0.1:15630, one GET endpoint returning two
fictional names. The broken policy stopped the host at startup; the fixed one answered a
curl.exe request that sent an Origin header. No browser was
involved: the message is the server's, not the browser console's.
Frequently asked
- Can I use AllowAnyOrigin with AllowCredentials in ASP.NET Core?
- No. The policy builder throws 'The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time'. List the origins with WithOrigins and keep AllowCredentials.
- When is the CORS wildcard and credentials error thrown?
- In the test it was thrown at startup, while UseCors created its middleware, so the host logged 'Application startup exception' and the app never listened for requests.
- How do I allow credentials for several front-end origins?
- Pass each origin, with its scheme and port as the browser sends it, to WithOrigins, then call AllowCredentials. The test used WithOrigins("http://localhost:5173") and the response echoed that origin with Access-Control-Allow-Credentials: true.
More decoded errors in the Fixes category. If the app runs but the browser says the header is missing, read the CORS post about a missing Access-Control-Allow-Origin header.