✅ Cors not adding headers on ASP.NET application
I have a asp.net core web app, that will receive calls from a different origin (different port). To test, I have the following code in the
Program.cs
of the ASP.NET application.
var app = builder.Build();
app.UseCors(builder => {
builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
});
app.UseAuthentication();
app.UseAuthorization();
app.CreateDbIfNotExists();
// Configure the HTTP request pipeline.
app.MapGrpcService<PatientServiceGrpc>();
app.MapGrpcService<AuthenticateServiceGrpc>();
app.MapGrpcService<AdminServiceGrpc>();
app.MapGet("/",
() =>
"Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.Run();
However, I can't make calls to the api through the frontend, since the responses don't contain the Access-Control-Allow-Origin
header, even though I allow all origins. What am I missing here?5 Replies
using
.WithOrigins()
for reading origins from appsettings is easy to implement, if you want to avoid AllowAnyOrigin or test/debug a different approach
but i wouldn't know how to check that cors is enabled on minimal apis
i have only classic controllers when i use EnableCors
attributeI know, the issue is that even with allowing all origins, it doesn't work. Maybe because I'm using GRPC.
I followed these instructions here: https://learn.microsoft.com/en-us/aspnet/core/grpc/grpcweb?view=aspnetcore-7.0 , but no dice so far...
gRPC-Web in ASP.NET Core gRPC apps
Learn how to configure gRPC services on ASP.NET Core to be callable from browser apps using gRPC-Web.
Ah, fixed it. Needed to also support HTTP/1
Jay 😄
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.