diff options
author | Marek Habersack <grendel@twistedcode.net> | 2009-06-06 01:26:49 +0400 |
---|---|---|
committer | Marek Habersack <grendel@twistedcode.net> | 2009-06-06 01:26:49 +0400 |
commit | 3325e79f38265ec4a20b443d8e24972184768054 (patch) | |
tree | df1e5ae8b4d0afbe70ae890e21c017df16a5b0f4 /mcs | |
parent | 14c36e347e258d4b77073863ad6284b43c41b55a (diff) |
Backport of r130909
svn path=/branches/mono-2-4/mcs/; revision=135562
Diffstat (limited to 'mcs')
6 files changed, 101 insertions, 2 deletions
diff --git a/mcs/class/System.Web/System.Web.Configuration_2.0/ApplicationSettingsConfigurationFileMap.cs b/mcs/class/System.Web/System.Web.Configuration_2.0/ApplicationSettingsConfigurationFileMap.cs new file mode 100644 index 00000000000..a34d4a378f4 --- /dev/null +++ b/mcs/class/System.Web/System.Web.Configuration_2.0/ApplicationSettingsConfigurationFileMap.cs @@ -0,0 +1,51 @@ +// +// System.Web.Configuration.ApplicationSettingsConfigurationFileMap.cs +// +// Authors: +// Marek Habersack (mhabersack@novell.com) +// +// Copyright (C) 2009 Novell, Inc (http://novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +#if NET_2_0 +using System; +using System.Configuration; +using System.Web; +using System.Web.Configuration; + +namespace System.Web.Configuration +{ + // Part of fix for bug #491531 + class ApplicationSettingsConfigurationFileMap : ConfigurationFileMap + { + public ApplicationSettingsConfigurationFileMap () + { + HttpContext ctx = HttpContext.Current; + HttpRequest req = ctx != null ? ctx.Request : null; + + if (req != null) { + MachineConfigFilename = WebConfigurationHost.GetWebConfigFileName (req.MapPath (WebConfigurationManager.FindWebConfig (req.CurrentExecutionFilePath))); + } else + MachineConfigFilename = null; + } + } +} +#endif
\ No newline at end of file diff --git a/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog b/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog index 6eb64070bed..73c017a1394 100644 --- a/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog +++ b/mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog @@ -21,6 +21,15 @@ * HttpHandlersSection.cs: if we're matching a default handler, disallow caching. +2009-04-03 Marek Habersack <mhabersack@novell.com> + + * WebConfigurationManager.cs: added code in the static constructor + to enable retrieving application settings via + ApplicationSettingsBase from within asp.net applications. Fixes + bug #491531 + + * ApplicationSettingsConfigurationFileMap.cs: added. + 2009-03-12 Dean Brettle <dean@brettle.com> * nBrowser/Build.cs: made Browser() method thread-safe and moved the diff --git a/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs b/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs index 011b45632c4..3435e7dd9fa 100644 --- a/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs +++ b/mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationManager.cs @@ -164,6 +164,14 @@ namespace System.Web.Configuration { PropertyInfo prop = typeof(ConfigurationManager).GetProperty ("ConfigurationFactory", BindingFlags.Static | BindingFlags.NonPublic); if (prop != null) configFactory = prop.GetValue (null, null) as IInternalConfigConfigurationFactory; + + // Part of fix for bug #491531 + Type type = Type.GetType ("System.Configuration.CustomizableFileSettingsProvider, System", false); + if (type != null) { + FieldInfo fi = type.GetField ("webConfigurationFileMapType", BindingFlags.Static | BindingFlags.NonPublic); + if (fi != null && fi.FieldType == Type.GetType ("System.Type")) + fi.SetValue (null, typeof (ApplicationSettingsConfigurationFileMap)); + } } public static _Configuration OpenMachineConfiguration () @@ -388,7 +396,7 @@ namespace System.Web.Configuration { return curPath.Substring (0, idx); } - static string FindWebConfig (string path) + internal static string FindWebConfig (string path) { if (String.IsNullOrEmpty (path)) return path; @@ -421,7 +429,7 @@ namespace System.Web.Configuration { curPath = rootPath; break; } - + if (WebConfigurationHost.GetWebConfigFileName (physPath) != null) break; diff --git a/mcs/class/System.Web/System.Web.dll.sources b/mcs/class/System.Web/System.Web.dll.sources index 57da2975565..189450f0346 100644 --- a/mcs/class/System.Web/System.Web.dll.sources +++ b/mcs/class/System.Web/System.Web.dll.sources @@ -140,6 +140,7 @@ System.Web.Configuration/WebConfigurationSettings.cs System.Web.Configuration/WebControlsSectionHandler.cs System.Web.Configuration_2.0/AdapterDictionary.cs System.Web.Configuration_2.0/AnonymousIdentificationSection.cs +System.Web.Configuration_2.0/ApplicationSettingsConfigurationFileMap.cs System.Web.Configuration_2.0/AssemblyCollection.cs System.Web.Configuration_2.0/AssemblyInfo.cs System.Web.Configuration_2.0/AuthenticationSection.cs diff --git a/mcs/class/System/System.Configuration/ChangeLog b/mcs/class/System/System.Configuration/ChangeLog index 5631c73cd16..d1affb8787f 100644 --- a/mcs/class/System/System.Configuration/ChangeLog +++ b/mcs/class/System/System.Configuration/ChangeLog @@ -3,6 +3,11 @@ * CustomizableFileSettingsProvider.cs: make sure 'values' is initialized in Reset(). Fixes bug #436592. +2009-04-03 Marek Habersack <mhabersack@novell.com> + + * CustomizableFileSettingsProvider.cs: added a way for System.Web + to specify path to the current Web.config. Fixes bug #491531 + 2008-11-20 Gonzalo Paniagua Javier <gonzalo@novell.com> * ConfigHelper.cs: allow xmlns attribute. diff --git a/mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs b/mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs index 988f6a91857..49e62388a7a 100644 --- a/mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs +++ b/mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs @@ -71,6 +71,17 @@ namespace System.Configuration internal class CustomizableFileSettingsProvider : SettingsProvider, IApplicationSettingsProvider { + // KLUDGE WARNING. + // + // This is used from within System.Web to allow mapping of the ExeConfigFilename to + // the correct Web.config for the current request. Otherwise web applications will + // not be able to access settings from Web.config. The type assigned to this + // variable must descend from the ConfigurationFileMap class and its + // MachineConfigFilename will be used to set the ExeConfigFilename. + // + // This is necessary to fix bug #491531 + private static Type webConfigurationFileMapType; + private static string userRoamingPath = ""; private static string userLocalPath = ""; private static string userRoamingPathPrevVersion = ""; @@ -783,12 +794,26 @@ namespace System.Configuration // current version exeMapCurrent = new ExeConfigurationFileMap (); + // exeMapCurrent.ExeConfigFilename = System.Windows.Forms.Application.ExecutablePath + ".config"; Assembly entry = Assembly.GetEntryAssembly () ?? Assembly.GetExecutingAssembly (); exeMapCurrent.ExeConfigFilename = entry.Location + ".config"; exeMapCurrent.LocalUserConfigFilename = UserLocalFullPath; exeMapCurrent.RoamingUserConfigFilename = UserRoamingFullPath; + if (webConfigurationFileMapType != null && typeof (ConfigurationFileMap).IsAssignableFrom (webConfigurationFileMapType)) { + try { + ConfigurationFileMap cfgFileMap = Activator.CreateInstance (webConfigurationFileMapType) as ConfigurationFileMap; + if (cfgFileMap != null) { + string fpath = cfgFileMap.MachineConfigFilename; + if (!String.IsNullOrEmpty (fpath)) + exeMapCurrent.ExeConfigFilename = fpath; + } + } catch { + // ignore + } + } + // previous version if ((PrevUserLocalFullPath != "") && (PrevUserRoamingFullPath != "")) { |