System.Web.Hosting.ApplicationHost.CreateApplicationHost C# (CSharp) Méthode

CreateApplicationHost() private méthode

private CreateApplicationHost ( Type hostType, string virtualDir, string physicalDir ) : object
hostType System.Type
virtualDir string
physicalDir string
Résultat object
		public static object CreateApplicationHost (Type hostType, string virtualDir, string physicalDir)
		{
			if (physicalDir == null)
				throw new NullReferenceException ();

			// Make sure physicalDir has file system semantics
			// and not uri semantics ( '\' and not '/' ).
			physicalDir = Path.GetFullPath (physicalDir);

			if (hostType == null)
				throw new ArgumentException ("hostType can't be null");

			if (virtualDir == null)
				throw new ArgumentNullException ("virtualDir");

			Evidence evidence = new Evidence (AppDomain.CurrentDomain.Evidence);
			
			//
			// Setup
			//
			AppDomainSetup setup = new AppDomainSetup ();

			setup.ApplicationBase = physicalDir;

			setup.ConfigurationFile = FindWebConfig (physicalDir);
			setup.DisallowCodeDownload = true;

			string[] bindirPath = new string [1] {
#if NET_2_0
				Path.Combine (physicalDir, "bin")
#else
				"bin"
#endif
			};
			string bindir;

			foreach (string dir in HttpApplication.BinDirs) {
				bindir = Path.Combine (physicalDir, dir);
			
				if (Directory.Exists (bindir)) {
#if NET_2_0
					bindirPath [0] = bindir;
#else
					bindirPath [0] = dir;
#endif
					break;
				}
			}

			setup.PrivateBinPath = BuildPrivateBinPath (physicalDir, bindirPath);
			setup.PrivateBinPathProbe = "*";
			string dynamic_dir = null;
			string user = Environment.UserName;
			int tempDirTag = 0;
			string dirPrefix = String.Concat (user, "-temp-aspnet-");
			
			for (int i = 0; ; i++){
				string d = Path.Combine (Path.GetTempPath (), String.Concat (dirPrefix, i.ToString ("x")));
			
				try {
					CreateDirectory (d);
					string stamp = Path.Combine (d, "stamp");
					CreateDirectory (stamp);
					dynamic_dir = d;
					try {
						Directory.Delete (stamp);
					} catch (Exception) {
						// ignore
					}
					
					tempDirTag = i.GetHashCode ();
					break;
				} catch (UnauthorizedAccessException){
					continue;
				}
			}
			// 
			// Unique Domain ID
			//
			string domain_id = (virtualDir.GetHashCode () + 1 ^ physicalDir.GetHashCode () + 2 ^ tempDirTag).ToString ("x");

			// This is used by mod_mono's fail-over support
			string domain_id_suffix = Environment.GetEnvironmentVariable ("__MONO_DOMAIN_ID_SUFFIX");
			if (domain_id_suffix != null && domain_id_suffix.Length > 0)
				domain_id += domain_id_suffix;
			
			setup.ApplicationName = domain_id;
			setup.DynamicBase = dynamic_dir;
			setup.CachePath = dynamic_dir;

			string dynamic_base = setup.DynamicBase;
			if (CreateDirectory (dynamic_base) && (Environment.GetEnvironmentVariable ("MONO_ASPNET_NODELETE") == null))
				ClearDynamicBaseDirectory (dynamic_base);

			//
			// Create app domain
			//
			AppDomain appdomain;
			appdomain = AppDomain.CreateDomain (domain_id, evidence, setup);

			//
			// Populate with the AppDomain data keys expected, Mono only uses a
			// few, but third party apps might use others:
			//
			appdomain.SetData (".appDomain", "*");
			int l = physicalDir.Length;
			if (physicalDir [l - 1] != Path.DirectorySeparatorChar)
				physicalDir += Path.DirectorySeparatorChar;
			appdomain.SetData (".appPath", physicalDir);
			appdomain.SetData (".appVPath", virtualDir);
			appdomain.SetData (".appId", domain_id);
			appdomain.SetData (".domainId", domain_id);
			appdomain.SetData (".hostingVirtualPath", virtualDir);
			appdomain.SetData (".hostingInstallDir", Path.GetDirectoryName (typeof (Object).Assembly.CodeBase));
#if NET_2_0
			appdomain.SetData ("DataDirectory", Path.Combine (physicalDir, "App_Data"));
#endif
			appdomain.SetData (MonoHostedDataKey, "yes");
			
#if NET_2_0
			appdomain.DoCallBack (SetHostingEnvironment);
#endif
			return appdomain.CreateInstanceAndUnwrap (hostType.Module.Assembly.FullName, hostType.FullName);
		}

Usage Example

        BareApplicationHost CreateHost(string appId, string vpath, string ppath)
        {
            BareApplicationHost host;

            host               = (BareApplicationHost)ApplicationHost.CreateApplicationHost(typeof(BareApplicationHost), vpath, ppath);
            host.Manager       = this;
            host.AppID         = appId;
            id_to_host [appId] = host;
            return(host);
        }