2007-10-17 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Tue, 16 Oct 2007 22:34:48 +0000 (22:34 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Tue, 16 Oct 2007 22:34:48 +0000 (22:34 -0000)
* ApplicationHost.cs: introduce an application domain data item to
allow checks for whether System.Web code runs inside a hosted
application or in a stand-alone one.
Made the array of web.config name variations an internal one, to
be used from within configuration code.

2007-10-17  Marek Habersack  <mhabersack@novell.com>

* WebConfigurationHost.cs: if running outside hosted environment,
read only the assemblyname.config configuration file instead of
web.config. Fixes bug #332425

svn path=/trunk/mcs/; revision=87621

mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog
mcs/class/System.Web/System.Web.Configuration_2.0/WebConfigurationHost.cs
mcs/class/System.Web/System.Web.Hosting/ApplicationHost.cs
mcs/class/System.Web/System.Web.Hosting/ChangeLog

index d6e4a4b5f84a8ff56db2b073da7dfa370c63d340..ad035d32add864508204f912c039ec4fff853a5a 100644 (file)
@@ -1,3 +1,9 @@
+2007-10-17  Marek Habersack  <mhabersack@novell.com>
+
+       * WebConfigurationHost.cs: if running outside hosted environment,
+       read only the assemblyname.config configuration file instead of
+       web.config. Fixes bug #332425
+
 2007-10-15  Marek Habersack  <mhabersack@novell.com>
 
        * ProvidersHelper.cs: use HttpApplication.LoadType instead of
index c9b1a4d2421fe3e72f84001f2b8b0343f3d970ba..254cf404758376fe5b0dfe9dd033529dd179cd9d 100644 (file)
@@ -34,6 +34,7 @@ using System.IO;
 using System.Security;
 using System.Configuration;
 using System.Configuration.Internal;
+using System.Web.Hosting;
 using System.Web.Util;
 using System.Reflection;
 
@@ -286,14 +287,30 @@ namespace System.Web.Configuration
                        if (file != null)
                                return file.FullName;
 #else
-                       string[] filenames = new string[] {"Web.Config", "Web.config", "web.config" };
+                       AppDomain domain = AppDomain.CurrentDomain;
+                       bool hosted = (domain.GetData (ApplicationHost.MonoHostedDataKey) as string) == "yes";
 
-                       foreach (string fn in filenames) {
-                               string file = Path.Combine (dir, fn);
-                               if (File.Exists (file))
-                                       return file;
-                       }
+                       if (hosted) {
+                               foreach (string fn in ApplicationHost.WebConfigFileNames) {
+                                       string file = Path.Combine (dir, fn);
+                                       if (File.Exists (file))
+                                               return file;
+                               }
 #endif
+                       } else {
+                               Assembly asm = Assembly.GetEntryAssembly () ?? Assembly.GetCallingAssembly ();
+                               string name = Path.GetFileName (asm.Location);
+                               string[] fileNames = new string[] {name + ".config", name + ".Config"};
+                               string appDir = domain.BaseDirectory;
+                               string file;
+
+                               foreach (string fn in fileNames) {
+                                       file = Path.Combine (appDir, fn);
+                                       if (File.Exists (file))
+                                               return file;
+                               }
+                       }
+                       
                        return null;
                }
 #if TARGET_J2EE
index 6ab6529596bdd33c981af34f71eda8cfd6eecc3a..542741d60d946cfcdfea4a84de7f65a0c4e316ae 100644 (file)
@@ -35,8 +35,9 @@ namespace System.Web.Hosting {
 
        // CAS - no InheritanceDemand here as the class is sealed
        [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
-       public sealed class ApplicationHost {           
-               static string [] types = { "Web.config", "Web.Config", "web.config" };
+       public sealed class ApplicationHost {
+               internal static readonly string MonoHostedDataKey = ".:!MonoAspNetHostedApp!:.";
+               internal static string [] WebConfigFileNames = { "Web.config", "Web.Config", "web.config" };
 
                private ApplicationHost ()
                {
@@ -46,7 +47,7 @@ namespace System.Web.Hosting {
                {
                        string r = null;
                                
-                       foreach (string s in types){
+                       foreach (string s in WebConfigFileNames){
                                r = Path.Combine (basedir, s);
 
                                if (File.Exists (r))
@@ -216,6 +217,8 @@ namespace System.Web.Hosting {
 #if NET_2_0
                        appdomain.SetData ("DataDirectory", Path.Combine (physicalDir, "App_Data"));
 #endif
+                       appdomain.SetData (MonoHostedDataKey, "yes");
+                       
                        return appdomain.CreateInstanceAndUnwrap (hostType.Module.Assembly.FullName, hostType.FullName);
                }
        }
index be7c8dfed0d099aeef9f7cd1414fd14a27336109..26138f0714e8ef96096df094994d50fc1b42b024 100644 (file)
@@ -1,3 +1,11 @@
+2007-10-17  Marek Habersack  <mhabersack@novell.com>
+
+       * ApplicationHost.cs: introduce an application domain data item to
+       allow checks for whether System.Web code runs inside a hosted
+       application or in a stand-alone one.
+       Made the array of web.config name variations an internal one, to
+       be used from within configuration code.
+
 2007-08-24  Marek Habersack  <mhabersack@novell.com>
 
        * ApplicationHost.cs: use ; as the separator with PrivateBinPath.