Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Configuration Settings - .NET Framework

RSS
Modified on Mon, Jun 22, 2020, 1:12 PM by Administrator Categorized as ASP·NET MVC, Azure, ·Net Framework

Overview

This article provides code which will retrieve configured settings regardless of whether the calling code is running within a Web API (which retrieve the settings from the web.config file's appSettings section) or an Azure Function app (which retrieves it from the settings configured on the Azure portal).

Code

public static string GetSetting(string name)
{
    var result = Environment.GetEnvironmentVariable(name);

    if (string.IsNullOrWhiteSpace(result))
    {
        result = ConfigurationManager.AppSettings[name];
    }

    return result;
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2020, Patrick Jasinski.