'How to determine if an asp.net app is running on an azure vm

We have an asp.net app that gets deployed to both On-Prem and on Azure VMs. We are trying to figure out how to configure the app so that when deployed on an Azure VM it will use Azure App Configuration Service, but when deployed On-Prem it will continue to use the settings in the config files?

How can we know on app start up whether or not we are deployed on an Azure VM?



Solution 1:[1]

If you can, I would recommend you add a special environment variable when you provision your Azure VM or deploy your application. If not, you may use Azure Instance Metadata Service to tell the code is running in Azure VMs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zhenlan Wang