CORS error with new app service

Craig Stone 1 Reputation point
2021-07-09T18:58:01.223+00:00

I have a Blazor webassembly that runs as an app service. It calls a .net core api also running as an app service in the same resource group. I set this up a while ago and it has been running with no issues. Now I wanted to add a second api. I created a new app service again in the same resource group, but I am getting CORS errors when I try to call the new api. I have the AddCors set in the api code. If I comment that out in the code and use the portal CORS settings, I then get a 500 internal server error.

I created another new app service and deployed the old api to it and it also gets the same issues. But it works fine when deployed to the old app service that was created a while ago.

What changed when creating a new app service? I noticed the app insights gets created by default now and that was not the case before. I tried creating a new app service without app insights turned on, but still the issues are there when calling any api code deployed to that app service.

Is there some setting on a new app service that can be changed to get this to work? What changes have been made to app services?

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,393 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,900 questions
0 comments No comments
{count} votes

2 answers

Sort by: Oldest
  1. JasonPan - MSFT 4,281 Reputation points Microsoft Vendor
    2021-07-30T06:14:16.507+00:00

    Hi @Craig Stone

    First of all, suppose there is a program named ServerA as the api interface. When other programs need to call the interface in ServerA, we usually set it in the code AddCors, or set it in IIS (the way it is reflected in the program) It can be in the web.config file of the project, in the azure webapp, it can be set in the portal).

    Suppose there is a webapp named ClientA that needs to call ServerA's interface, then in ServerA's portal, the easiest way is to add ClientA's domain name in the figure below. Assuming that any other programs are also adding other domain names in ServerA.

    Please follow the methods below to troubleshoot the error you are currently experiencing:

    1. First of all, in the webapp you will be called, you don’t need to use the AddCors method in the code to control cross-domain issues. Fill in * in the CORS of the portal. Then perform your previous test, (please make sure you are called In the program, the above operation was carried out). *Explain the reason: Filling in * is to ensure that you have not made other wrong configurations, which may cause problems.* 119188-image.png
    2. If according to step 1, the program can be called normally without cross-domain error, then please fill in the called webapp (assuming it is server), and it will visit his webapps
      (Client side) URL.
    3. If the problem persists, it is recommended to create a new resource group, create a new webapp, redeploy and test.

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Jason

    0 comments No comments

  2. Craig Stone 1 Reputation point
    2021-07-30T23:41:02.28+00:00

    Thanks, Jason.
    I did find that the problem must lie in the Azure DevOps build/release process. If I publish the code directly from Visual Studio I do not have any CORS issues.
    I haven't looked into what the difference is from publishing in VS versus using the DevOps pipelines.
    If you have any ideas, let me know!