CloudConfigurationManager vs WebConfigurationManager?

后端 未结 4 1388
-上瘾入骨i
-上瘾入骨i 2021-01-04 03:25

In an Azure Websites I was always using the following code to fetch some values from the config\'s app settings:

string property = WebConfigurationManager.         


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 03:52

    CloudConfigurationManager enables us to read configuration file regardless of the environment we are in.

    So instead of writing environment specific code statements e.g., for web.config file:

    WebConfigurationManager.AppSettings["MySetting"]

    For ServiceConfiguration.cscfg file:

    RoleEnvironment.GetConfigurationSettingValue("MySetting")

    We can write the below statement, which will read values from all the configuration files i.e., app.config, web.config and ServiceConfiguration.cscfg.

    CloudConfigurationManager.GetSetting("MySetting")

提交回复
热议问题