Skip to content

Commit

Permalink
Merge pull request #45 from vasily-kirichenko/appSettings-web
Browse files Browse the repository at this point in the history
fixed: AppSettingsProvider cannot find web.config
  • Loading branch information
vasily-kirichenko committed Dec 6, 2014
2 parents 8805bf7 + 9d00c38 commit 1ca63b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/FSharp.Configuration/AppSettingsProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ open System
open System.Configuration
open System.Collections.Generic
open System.Globalization
open System.IO

let private getConfig() =
if Web.HttpContext.Current <> null && not (Web.HttpContext.Current.Request.PhysicalPath = "") then
Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
else
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

let getConfigValue(key) =
let settings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings
let settings = getConfig().AppSettings.Settings
settings.[key].Value

let setConfigValue(key, value) =
let settings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
settings.AppSettings.Settings.[key].Value <- value
settings.Save()
let config = getConfig()
config.AppSettings.Settings.[key].Value <- value
config.Save()

let getConnectionString(key: string) =
let connectionStrings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).ConnectionStrings.ConnectionStrings
Expand Down
6 changes: 4 additions & 2 deletions src/FSharp.Configuration/FSharp.Configuration.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -26,7 +26,8 @@
</DocumentationFile>
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe</StartProgram>
<StartArguments>l:\git\FSharp.Configuration\FSharp.Configuration.Tests.sln</StartArguments>
<StartArguments>
</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -48,6 +49,7 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 1ca63b4

Please sign in to comment.