Skip to content

Instantly share code, notes, and snippets.

@baronfel
Last active March 28, 2016 19:53
Show Gist options
  • Save baronfel/f604b24b430c842da538 to your computer and use it in GitHub Desktop.
Save baronfel/f604b24b430c842da538 to your computer and use it in GitHub Desktop.
get appsettings and merge from hosting web site
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