Retrieve Azure AppSettings and Connection String Settings in ASP.NET Core Apps

Raymond Raymond visibility 16,402 event 2017-10-10 access_time 4 years ago language English


In ASP.NET Core, we can easily use user secrets to manage our password or credentials. This post will summarize the approaches we can use after the websites are deployed into Azure.

Azure AppSettings & Connection Strings

In Azure management portal, navigate your App Services. And then in SETTINGS section, click on Application settings.
In App settings section, you can setup up any key way pairs:


In Connection strings section, you can setup all the connection strings:


You can also choose the connection type:


These settings are injected at run time.

Access App settings and Connection strings in your application


All the configurations will be injected and can accessed through IConfiguration. You can directly add IConfiguration into your controller or services. You can also inject this directly into your views.

Sample code in Controller

using AzureWebAppTest.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Diagnostics;

namespace AzureWebAppTest.Controllers
     public class HomeController : Controller
         private readonly IConfiguration configuration;

        public HomeController(IConfiguration configuration)
             this.configuration = configuration;

        public IActionResult Index()
             var appSettingTest1 = configuration["appSettingTest1"];
             var connectionStringTest1 = configuration.GetConnectionString("connectionStringTest1");

            return Json(new { appSettingTest1, connectionStringTest1 });


Sample configuration in Azure


Result in Azure website


Sample code in View

     ViewData["Title"] = "Home Page";
     Layout = null;
@using Microsoft.Extensions.Configuration
@inject Microsoft.Extensions.Configuration.IConfiguration configuration

<p>appSettingTest1: @configuration["appSettingTest1"]</p>
<p>connectionStringTest1: @configuration.GetConnectionString("connectionStringTest1")</p>

Result in Azure website


Access through environment variables

All these settings are injected into environment variables and you can access them in other programming languages by adding some prefix:

For App settings, ‘APPSETTING_’ is added to each settings. and for connection strings, there are different prefixes added for different connection types:


For more details, please refer to:

Update these settings in CI/CD environment

Instead of manually updating these settings through Azure management portal, you can also Azure Resource Manager PowerShell module to implement it in a continuous integration and deployment environment. Refer the following post for examples:


If you are using Visual Studio online build and release functions, you can also just install some extensions available in Visual Studio marketplace. For instance, the following link provide you the functionality to configure App settings:

More from Kontext
info Last modified by Administrator 4 years ago copyright This page is subject to Site terms.
comment Comments
V access_time 4 months ago more_vert

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts