
In this Azure tutorial, we will discuss How To Access App Setting Azure Functions. Along with this, we will also discuss a few other topics like How to Access the App settings in Azure Functions Runtime Version 3, Azure Functions v3 configuration, How to Access the App settings in Azure Functions Runtime Version 1, How to access application settings in Azure Functions (ASP.NET Core), Azure Function App Settings JSON.
How To Access App Setting Azure Functions? There are different ways to access the App settings using C# code based on different Azure Function Versions
- For the Azure Function Version V3, we can use the using statement in the code i.e using Microsoft.Extensions.Configuration. Along with this, we need to make a few changes in the local.settings.json file.
We will discuss How To Access App Setting Azure Functions from the C# code in detail below.
Table of Contents
How To Access App Setting Azure Functions
Well, Let’s Discuss How to access Azure Function Application Settings from C#. As part of the discussion, we will discuss How to access application settings in different runtime versions of Azure Functions.
How to Access the App Settings in Azure Functions Runtime Version 3
In the Azure Functions Runtime Versions 3, Accessing the Application Settings is a bit easier compared to the other Azure Functions Runtime Versions like Azure Function Version V2 and Azure Function Version V1.
Here are a few important things we need to remember like we must add the using statement i.e. using Microsoft.Extensions.Configuration. Along with this while implementing inside the Azure Function code we need to add the ExecutionContext context as an injection parameter to the Azure Function.
If We will consider an example here, we can see My Azure Function Code as below
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Extensions.Configuration;
namespace FunctionApp5
{
public static class MyProductHTTPFunction
{
[FunctionName("MyProductHTTPFunction")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
log.LogInformation("MyProductHTTPFunction function processed a request.");
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
string myappsettingsValue = configurationBuilder["appsettingkey"];
You can concentrate few lines of code that are a must to access the App settings in Azure Functions Runtime Version 3 as highlighted below

We are reading the app settings key value from the local.settings.json file, So we need to make a few changes in that file as well. So your local.settings.json file should look like below.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"appsettingkey": "Your App Settings key value"
}
}
How to Access the App Settings in Azure Functions Runtime Version 1
If we go back to the Older version of Azure Functions i.e. Runtime version 1 then we can see there, we were using the ConfigurationManager.
For example, the implementation was like below
var yourclientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"];
var yourclientSecret = System.Configuration.ConfigurationManager.AppSettings["ClientSecret"];
var youraad = System.Configuration.ConfigurationManager.AppSettings["AADDomain"];
Now we are not using the ConfigurationManager, instead, we are using the ConfigurationBuilder from the Azure Function runtime version V2 onwards.
How to access application settings in Azure Functions (ASP.NET Core)
Earlier in the case of Azure Function Runtime version V1, We were using the ConfigurationManager. But then on the latest versions of Azure Function, we are using the ConfigurationBuilder instead.
We can also use the System.Environment.GetEnvironmentVariable to read the application settings or app settings.
his is one of the recommended ways. The syntax will be like this
var value = Environment.GetEnvironmentVariable("Put the key value");
For local development, You can add some custom settings in your local.settings.json file. One very important point to note here is that the settings you are adding in the local.settings.json file will be useful for your local development once you will deploy to Azure you will not get that reference. So, this is one you can keep in your mind.
You just need to add one more key and value in the Local.settings.json file
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"custom key": "custom value"
}
}
The Azure function will look something like below
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Extensions.Configuration;
namespace FunctionApp5
{
public static class MyNewHTTPFunction
{
[FunctionName("MyNewHTTPFunction
")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
log.LogInformation("MyProductHTTPFunction function processed a request.");
var newconfiguration = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var appSettingsVal = newconfiguration["appSettingKey"];
var myconnection = newconfiguration.GetConnectionString("YourSqlConnectionString");
in the above code, we are adding the optional: true, this is because the local.settings.json file reference we will not get once deployed to Azure.
Azure Function App Settings JSON
One important thing to note here is that Appsettings.json has already deprecated from long back. That was the old name for the local.settings.json file. The new file is the local.settings.json file now. All the configurations for the Azure Functions
Manage Application Settings for Azure Functions within Visual Studio
When you are working with the Azure Function If you want to Add, Edit, or Delete any of the application settings. We normally log in to the Azure Portal and navigate to our Azure function app and then from the Application settings section, we use to perform all the operations as shown below.

But there is one more way that you can Manage the Application settings from the Visual Studio itself. If you can see the below screenshot, we can click on the Edit Azure App Service settings link as highlighted below.

If you click on the + Add Setting, you can able to see the below window to add the App settings.

FAQs
How do I access application settings in Azure
Above, we have already discussed this with examples, I will just explain with specific to the point here.
Step-1: Install the required Nuget packages
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.Json
Microsoft.Extensions.Configuration.FileExtensions
Step 2: Use the below-using statement.
using Microsoft.Extensions.Configuration;
Step 3: Add the ExecutionContext as a parameter to your Azure Function
[FunctionName("MyNewHTTPFunction
")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
Step 4: Now you need to get the IConfiguration
 Root using the below lines of Code.
var myConfig = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
Step-5: The next step is to refer to the AppSettings Keys
var appSettingsVal = newconfiguration["appSettingKey"];
This is how to access the app setting Azure Functions.
How Do I Add A Connection String In Azure
One of the best ways is, You add a connection string for your Azure Function App. To do that you can follow the below steps
Log in to the Azure Portal.
Navigate to your Azure Function App
On the function App page, you can click on the Configuration from the left side menu —> Click on the Application Settings tab from the top and Now click on the + New connection string button as highlighted below to create the new connection string.

Now you have created the Connection string for your Azure Function, To read that from your code you can use the code format below
var myconn = System.Configuration.ConfigurationManager
.ConnectionStrings["MyConnection"].ConnectionString;
In this case, if you are trying to use other than the .Net language, then you can use the Application settings With the help of the Environment variable, you can easily able to access the App settings from your code.
You may also like following the below Articles
- Azure Function Environment Variable
- What Modules Are Available In Azure Functions PowerShell
- Web deployment task failed – cannot modify the file on the destination because it is locked by an external process
- How To Add Custom Modules to Azure Functions App
Wrapping Up
Well, in this article, we discussed How To Access App Setting Azure Functions, How to Access the App settings in Azure Functions Runtime Version 3, Azure Functions v3 configuration and we also discussed How to Access the App settings in Azure Functions Runtime Version 1, How to access application settings in Azure Functions (ASP.NET Core), Azure Function App Settings JSON. Hope you have enjoyed this article !!!.