Azure App Service: Difficulty Configuring CORS for SPA with Custom Domain
I'm having trouble configuring CORS for my Single Page Application (SPA) hosted on Azure App Service with a custom domain. The app works perfectly when accessed via the default Azure domain, but when I try to access it through my custom domain, I'm getting CORS errors in the browser console: ``` Access to XMLHttpRequest at 'https://api.mycustomdomain.com/data' from origin 'https://myapp.mycustomdomain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. ``` I've set up CORS in the Azure portal by adding my custom domain to the allowed origins under the CORS settings. Hereβs what I have tried so far: 1. Verified that the API Iβm calling has the correct headers set in its own configuration. 2. Confirmed that CORS settings in Azure App Service are saved and reflect both my custom domain and wildcard (`*`), but I'm still working with issues. 3. Used Postman to test the API calls, which work correctly without CORS issues. 4. Checked the network requests in the browser, and the response from the API does not include the `Access-Control-Allow-Origin` header. Here's the CORS configuration code I tried to implement in my ASP.NET Core API: ```csharp public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowSpecificOrigin", builder => builder.WithOrigins("https://myapp.mycustomdomain.com") .AllowAnyHeader() .AllowAnyMethod()); }); services.AddControllers(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseCors("AllowSpecificOrigin"); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } ``` Despite all this, the CORS policy is still blocking my requests from the SPA. I suspect that there's possibly something wrong with the routing or the configuration in Azure itself. Any insights on how to fix this scenario? Are there any other configurations I might be missing? How would you solve this?