Configuration Settings - .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;
}