languageEnglish

Read Environment Variables in .NET Azure Functions

visibility 9 comment 0 access_time 25 days ago

.NET Azure Functions can consume environment variables directly as any other .NET applications using System.Environment class. 

Code snippet

The following code snippet reads an environment variable named DefaultConnection

    public class Program
    {
        public static void Main()
        {
            var dbConnString = Environment.GetEnvironmentVariable("DefaultConnection");
        }
    }

The value of the variable can be stored in your system level environment variables or in development environment, it can be stored in local.settings.json file.

{
  "IsEncrypted": false,
  "Values": {
    "DefaultConnection": "Server=.;Database=mydb;Trusted_Connection=True;MultipleActiveResultSets=true",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

In Azure production environment, the variables can be configured in the portal or via CLI tools or other SDKs:


copyright This page is subject to Site terms.

Subscribe newsletter

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext

Run .NET 5 on Azure App Services
visibility 407
thumb_up 0
access_time 12 months ago
visibility 9598
thumb_up 0
access_time 2 years ago