Last active
March 28, 2016 19:53
-
-
Save baronfel/f604b24b430c842da538 to your computer and use it in GitHub Desktop.
get appsettings and merge from hosting web site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let localSettings = System.Web.Configuration.WebConfigurationManager.AppSettings | |
let hostSiteSettings = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Default Web Site") |> Option.ofObj |> Option.map (fun config -> config.AppSettings.Settings) | |
let allSettings = | |
seq { | |
match hostSiteSettings with | |
| None -> () | |
| Some settings -> | |
for key in settings.AllKeys do | |
yield (key, settings.[key].Value) | |
for key in localSettings.Keys do | |
yield (key, localSettings.[key]) | |
} |> Map // using a map here makes it so that if we have any keys in the local config that clobber a key in the appsettings, we overwrite it instead of a duplicatekeyexception from a dictionary add. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment