使用CloudConfigurationManager,你可以在你的应用程序中访问AppSettings,或者如果在Azure的上下文中运行,则改为门户设置(如果值存在的话)。但是我还没有看到进入配置文件的ConnectionStrings部分的方法,甚至没有看到门户设置。我应该寻找什么对象?
发布于 2015-10-08 01:20:49
请注意,为了使用CloudConfigurationManager读取app.config文件,您必须在appSettings标记中指定配置设置...CloudConfigurationManager只能读取appSettings标记中的配置设置。
发布于 2015-12-12 12:25:03
我刚刚在微软的一个github账户上发现了AmbientConnectionStringProvider。这反过来又使用了ConfigurationUtility class。然后,ConfigurationUtility执行以下操作:
public static string GetConnectionFromConfigOrEnvironment(string connectionName)
{
string configValue = null;
var connectionStringEntry = ConfigurationManager.ConnectionStrings[connectionName];
if (connectionStringEntry != null)
{
configValue = connectionStringEntry.ConnectionString;
}
if (!string.IsNullOrEmpty(configValue))
{
// config values take precedence over environment values
return configValue;
}
return Environment.GetEnvironmentVariable(connectionName) ?? configValue;
}这种方法可能就是我想要的。
发布于 2016-06-30 02:51:34
事实证明,对于我的AppSettings和ConnectionStrings,我都可以使用常规的ol‘ConfigurationManager。
它足够智能,可以知道我何时在Azure中运行,以及何时在本地运行。
https://stackoverflow.com/questions/32991264
复制相似问题