Strip prefix off when reading connection strings from Azure WebSites

This commit is contained in:
Wei Wang 2014-04-07 17:00:39 -07:00
Родитель d28d56c316
Коммит 78e2fe5e4a
1 изменённых файлов: 4 добавлений и 0 удалений

Просмотреть файл

@ -7,6 +7,7 @@ namespace Microsoft.AspNet.ConfigurationModel.Sources
public class EnvironmentVariablesConfigurationSource : BaseConfigurationSource
{
private readonly string _prefix;
private static readonly string AzureConnStrPrefix = "SQLAZURECONNSTR_";
public EnvironmentVariablesConfigurationSource(string prefix)
{
@ -22,6 +23,9 @@ namespace Microsoft.AspNet.ConfigurationModel.Sources
{
ReplaceData(Environment.GetEnvironmentVariables()
.Cast<DictionaryEntry>()
.Select(entry =>
((string)entry.Key).StartsWith(AzureConnStrPrefix, StringComparison.OrdinalIgnoreCase) ?
new DictionaryEntry(((string)entry.Key).Substring(AzureConnStrPrefix.Length), entry.Value) : entry)
.Where(entry => ((string)entry.Key).StartsWith(_prefix, StringComparison.OrdinalIgnoreCase))
.ToDictionary(
entry => ((string)entry.Key).Substring(_prefix.Length),