How to define and use Application Settings in your Azure Functions

As it is stated in the Azure Portal Application settings are encrypted at rest and transmitted over an encrypted channel. You can choose to display them in plain text in your browser by using the controls below. Application Settings are exposed as environment variables for access by your application at runtime.

Storing sensitive data as application settings is preferred over having them in plain text in your code. In this article we are going to see how to define them in your Azure Portal, how to integrate them in your Function-code and how to give them values when you are debugging your Functions locally.

Define an Application Setting in Azure Portal

You can find the application settings of your Function under the Configuration option. From there add a new application setting, define the name of the setting and its value:

Azure Function - Configuration - Application Settings

Get the value of an Application Setting in your Function-code

To get the value of a setting in your Function use the following code Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process); where name is the name of the setting you want to read. This returns a string which you will have to cast to the needed type.

Debug Functions which use Application Settings

When you are debugging your Functions with F5 locally, the application settings stored in the Azure Portal are not getting read. You will have to store them and their values locally. For that you can use a local.settings.json file and write the settings then inside a Values object. Pay attention on the IsEncrypted property which is needed so that you avoid the Failed to decrypt settings. Encrypted settings only be edited through 'func settings add'. when your Functions start locally. For this issue, you can check more inStackOverflow.

Do not forget to set the local.settings.json file in your .gitignore file, so that your sensitive data are not getting checked in!! The local.settings.json file is for local use only!

public class NameNotEmptyValidationRule : IValidationRule
  "IsEncrypted": false,
  "Values": {
    "ApplicationSetting1": "1.0",
    "ApplicationSetting2": "ABCD"
comments powered by Disqus