I have an api published in Azure App Service which uses some custom headers. When I deployed the app and trying to configure CORS, there is no option to set Allowed Headers. Also ,there doesn’t seems to mention in Microsoft Docs about this thing. Can anyone let me know if we can set Allowed Headers for Azure App Services?
- Tried checking available options under App Service > Setting > API > CORS , App Service > Setting > Configurations
- Tried to look for official documents from Microsoft for CORS with Allowed Headers for Azure App Service.
All trials ended with no luck.
2
Answers
Azure App Service allows to configure CORS for web application, but it doesn’t provide a direct option to set
Allowed Headers
in the Azure Portal UI.To handle CORS in backend, we can set the allowed headers programmatically based on the framework.
Below is the Example of
Asp.net core
, I set the Cors in Program.cs File.Program.cs:
For
.Net Framework
I usedweb.config
file to set the Cors in Azure Web app service.I added the
web.config
file to the root directory of the Web Api.web.config:
Output:
For More Details refer this Ms Doc.
To set Allowed Headers for CORS in Azure App Services, you need to configure it within your application’s code, as the Azure Portal does not provide a direct option for this.
For ASP.NET Core applications, you can set CORS policies in your Startup.cs or Program.cs file.
Visit references provided:
link
link