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)
10 using System.Collections;
12 using System.Runtime.Remoting;
13 using System.Web.Util;
15 namespace System.Web.Hosting
17 public sealed class ApplicationHost
19 internal class ConfigInitHelper : MarshalByRefObject
21 internal void InitConfig ()
26 private ApplicationHost ()
30 public static object CreateApplicationHost (Type hostType,
35 throw new ArgumentException ("hostType");
37 if (virtualDir == null || virtualDir.Length == 0)
38 throw new ArgumentException ("virtualDir");
40 if (physicalDir == null || physicalDir.Length == 0)
41 throw new ArgumentException ("physicalDir");
43 if (physicalDir [physicalDir.Length - 1] != Path.DirectorySeparatorChar)
44 physicalDir += Path.DirectorySeparatorChar;
46 int nowInt = DateTime.Now.ToString ().GetHashCode ();
47 string nowHash = nowInt.ToString ("x");
48 nowInt += physicalDir.GetHashCode ();
49 string sum = nowInt.ToString ("x");
50 Hashtable hTable = new Hashtable ();
51 AppDomainSetup domainSetup = new AppDomainSetup();
53 AppDomainFactory.PopulateDomainBindings (nowHash,
61 AppDomain domain = AppDomain.CreateDomain (nowHash, null, domainSetup);
62 foreach (string key in hTable.Keys)
63 domain.SetData (key, (string) hTable [key]);
65 domain.SetData (".hostingVirtualPath", virtualDir);
66 domain.SetData (".hostingInstallDir", ICalls.GetMachineInstallDirectory ());
67 InitConfigInNewAppDomain (domain);
68 ObjectHandle o = domain.CreateInstance (hostType.Assembly.FullName,
73 private static void InitConfigInNewAppDomain (AppDomain appDomain)
75 Type t = typeof (ConfigInitHelper);
76 ObjectHandle o = appDomain.CreateInstance (t.Assembly.FullName, t.FullName);
77 ConfigInitHelper helper = (ConfigInitHelper) o.Unwrap();