Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4845

CORS blocks direct access to API from Blazor

$
0
0

I've setup an Aspire solution with a Blazor WebAssembly and an API projects. API runs on https://localhost:7476 and Blazor is served from https://localhost:7077. Generally any API registered with MapPost or MapGet is working as expected because by default Blazor app runs in InteractiveServer mode, so all APIs appear to be called via internal SignalR connection.

However for uploading files from the web, I need to hit the API endpoint directly. I'm using RadzenUpload component to do so, and I've configured it to hit https://localhost:7476/api/upload

However the browser gives me an error:

Access to XMLHttpRequest at 'https://localhost:7476/api/upload' from origin 'https://localhost:7077' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I've tried adding the following to both the API and the Blazor's Program.cs but that didn't help.Any help is greatly appreciated.

builder.Services.AddCors(o => o.AddPolicy("AllowAll", builder =>{    builder.AllowAnyOrigin()        .AllowAnyMethod()        .AllowAnyHeader();}));...var app = builder.Build();app.UseCors("AllowAll");

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>