C
C#2mo ago
Tobonautilus

✅ Added CORS feature to Blazor WASM - I cannot find the file to put it in

At first I'm a absolutely beginner, it may just a misuage or that my idea will not work in WASM. What I wanna achieve If the Blazor Wasm Page loads, I want to call a external RSS Feed to be loaded and the resulting data should be rendered. This fails because of a missing CORS-Feature. I googled and Copilot-ed it but I cannot find the spot where I must add it. It is always prints me: To add CORS (Cross-Origin Resource Sharing) to your Blazor WebAssembly application, you’ll need to configure it on the server that hosts your Blazor app, not directly within the Blazor WebAssembly Program.cs But I cannot find the file. My "ProjectName.Wasm" Program.cs looks like:
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSingleton<LifeService>();
builder.Services.AddSingleton<MediumService>();

await builder.Build().RunAsync();
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSingleton<LifeService>();
builder.Services.AddSingleton<MediumService>();

await builder.Build().RunAsync();
` ... and I think I do not have the other file that the pilot mentioned? Thanks for your assistant!
3 Replies
Tobonautilus
Tobonautilus2mo ago
!close
Accord
Accord2mo ago
Closed!
Tobonautilus
Tobonautilus2mo ago
Solution: It is not meant to work like that. WASM Standalone is just capable of using its own server's data