question

CraigStone-0756 avatar image
0 Votes"
CraigStone-0756 asked ZhiLv-MSFT commented

CORS error with new app service

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?

azure-webappsdotnet-aspnet-core-blazor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JasonPan-MSFT avatar image
0 Votes"
JasonPan-MSFT answered

Hi @CraigStone-0756

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




image.png (58.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CraigStone-0756 avatar image
0 Votes"
CraigStone-0756 answered ZhiLv-MSFT commented

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!

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @CraigStone-0756,

To the Azure DevOps issue, I suggest you could post the problem on the Developer Community Azure DevOps Forum.

0 Votes 0 ·