CloudConfigurationManager does not pick up ApplicationSettings from app.config

后端 未结 1 1763
天涯浪人
天涯浪人 2020-12-17 09:45

I have a library containing some Azure helper classes. Inside these helper classes I obtain settings such as the Azure account name and key. When running in Azure these sett

相关标签:
1条回答
  • 2020-12-17 10:17

    The CloudConfigurationManager only supports the AppSettings part of the web.config/app.config and will try to read values from here if the setting is missing from the Azure configuration. The documentation states that it won't read the web.config/app.config if the property RoleEnvironment.IsAvailable is true (running in Azure), but that is incorrect as we can see in the source code below (no check for IsAvailable).

    You can take a look at the source to see what happens:

        /// <summary>
        /// Gets a setting with the given name.
        /// </summary>
        /// <param name="name">Setting name.</param>
        /// <returns>Setting value or null if such setting does not exist.</returns>
        internal string GetSetting(string name)
        {
            Debug.Assert(!string.IsNullOrEmpty(name));
    
            string value = null;
    
            value = GetValue("ServiceRuntime", name, GetServiceRuntimeSetting);
            if (value == null)
            {
                value = GetValue("ConfigurationManager", name, n => ConfigurationManager.AppSettings[n]);
            }
    
            return value;
        }
    

    As you can see, there is only one call to the normal ConfigurationManager class that simply accesses the AppSettings.

    0 讨论(0)
提交回复
热议问题