Azure Static Web App (Blazor) problem with CORS
Hello, I have been developing a blazor wasm app that uses multi threading. The problem is that I don't know how can i set these headers
Cross-Origin-Embedder-Policy:require-corp
& Cross-Origin-Opener-Policy:same-origin
.
I tried to set them like the docs suggested in staticwebapp.config.json
like:
Still the headers are not set, but the workflow run passes anyway.
In local using dotnet serve it works that way: dotnet serve -h "Cross-Origin-Opener-Policy:same-origin" -h "Cross-Origin-Embedder-Policy:require-corp" --directory bin\Release\net9.0\publish\wwwroot
What am I doing wrong? Can somebody please give me a working staticwebapp.config.json
? Thank you 🙂
PS: The app is full client side, no api calls.11 Replies
@kopale. Have you configured cors?
Eeeh, I thought setting the json file is going to be enough. I just deployed the app used that config file. Where should I set that? This is my first time using azure 😅 .
I have this
I have something like this. It depends on your use case. Add
cors
to the service collection.Oh the app is blazor wasm and its not hosted, like no kestrel, the azure static web app serves the app
i have to configured at there somehow
@kopale. Take a look at this https://learn.microsoft.com/en-us/answers/questions/902766/cors-policy-with-wasm
CORS Policy with WASM - Microsoft Q&A
What is the requirement to have Blazor WASM call Web API hosted on the web server.
I have Web API hosted already on the web server which is good with Blazor server app,
Now I have the same service called by Blazor WASM, i get teh following error …
I have Web API hosted already on the web server which is good with Blazor server app,
Now I have the same service called by Blazor WASM, i get teh following error …
Thank you but like i said the host is the azure static web app, so i cant set cors in code because it is served by a file server (in my case azure) https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-9.0#standalone-deployment
Host and deploy ASP.NET Core Blazor WebAssembly
Learn how to host and deploy Blazor WebAssembly using ASP.NET Core, Content Delivery Networks (CDN), file servers, and GitHub Pages.
So there is no "host" in my code so I cant set cors there, thats why im tinkering in staticwebapp.config.json file
Like in my example on local im serving/"hosting" the app via dotnet serve
Jesus... the Azure documentation to put it lightly is so scattered all around. I tired bunch of configs, none of seems to work. Later I tried Cloudflare Pages and its working. You have to create and set '_headers' file (just paste this):
Deploy and boom it is working as expected. Still I would like to host it on Azure, can anybody help? Thank you 🙂
I'm not an expert but I think I got it working

this was with a slight modification to the template https://github.com/ryzngard/WASM_Static
GitHub
GitHub - ryzngard/WASM_Static
Contribute to ryzngard/WASM_Static development by creating an account on GitHub.
@lycian Thank you for taking the time to create an example 🙂 , I'm going to try it again later today
@lycian It works! Awesome, thank you again. 🙂
I believe the issue occurred because when Azure generated the configuration file through the online editor, it placed the file in the root of the GitHub repository instead of inside the intended app path (my case ./src/{ClientFolder}), even though I specified that path in the App location setting when creating the service.
