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.
You can add your keys and values by clicking the New application setting button.
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"
}
}