2 // System.Web.Hosting.ApplicationHost
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
6 // (class signature from Bob Smith <bob@thestuff.net> (C) )
7 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
33 using System.Runtime.Remoting;
34 using System.Web.Util;
36 namespace System.Web.Hosting
38 public sealed class ApplicationHost
40 internal class ConfigInitHelper : MarshalByRefObject
42 internal void InitConfig ()
47 private ApplicationHost ()
51 public static object CreateApplicationHost (Type hostType,
56 throw new ArgumentException ("hostType");
58 if (virtualDir == null || virtualDir.Length == 0)
59 throw new ArgumentException ("virtualDir");
61 if (physicalDir == null || physicalDir.Length == 0)
62 throw new ArgumentException ("physicalDir");
64 if (physicalDir [physicalDir.Length - 1] != Path.DirectorySeparatorChar)
65 physicalDir += Path.DirectorySeparatorChar;
67 int nowInt = DateTime.Now.ToString ().GetHashCode ();
68 string nowHash = nowInt.ToString ("x");
69 nowInt += physicalDir.GetHashCode ();
70 string sum = nowInt.ToString ("x");
71 Hashtable hTable = new Hashtable ();
72 AppDomainSetup domainSetup = new AppDomainSetup();
74 AppDomainFactory.PopulateDomainBindings (nowHash,
82 AppDomain domain = AppDomain.CreateDomain (nowHash, null, domainSetup);
83 foreach (string key in hTable.Keys)
84 domain.SetData (key, (string) hTable [key]);
86 domain.SetData (".hostingVirtualPath", virtualDir);
87 domain.SetData (".hostingInstallDir", ICalls.GetMachineInstallDirectory ());
88 InitConfigInNewAppDomain (domain);
89 ObjectHandle o = domain.CreateInstance (hostType.Assembly.FullName,
94 private static void InitConfigInNewAppDomain (AppDomain appDomain)
96 Type t = typeof (ConfigInitHelper);
97 ObjectHandle o = appDomain.CreateInstance (t.Assembly.FullName, t.FullName);
98 ConfigInitHelper helper = (ConfigInitHelper) o.Unwrap();