This content has 4 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Values hard coded to an application is the brightest “DO NOT” thing in software development. But how to bring your Azure Function more professional level?

Start using application settings

You can define key value pairs on the Microsoft Azure portal for your Function app. Go to your app and find the Settings section, and click on the configuration button.

Configuration item

You can add your keys and values by clicking the New application setting button.

Adding a new setting

Application Settings are exposed as environment variables for access by your application at runtime. Learn more

Access your settings from your code

You can access your newly created setting from C# using the GetEnvironmentVariable call.

System.Environment.GetEnvironmentVariable("yourvariablename");

What about local debugging?

You do not need to add and modify the environment variables in your operating system. Add a new json file to your solution called ‘local.settings.json’, and fill it up with some data like below:

{
  "IsEncrypted": false,
  "Values": {
    "yourvariablename": "fanncyyy!"
  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "*",
    "CORSCredentials": false
  },
  "ConnectionStrings": {
    "SecretSQL": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  }
}