private Host GetHost() { if (_shutdownInProgress) { return(null); } Host host = _host; if (host == null) { #if NET40 object obj2 = new object(); bool flag = false; try { Monitor.Enter(obj2 = _lockObject, ref flag); host = _host; if (host == null) { host = (Host)CreateWorkerAppDomainWithHost(_virtualPath, _physicalPath, typeof(Host)); host.Configure(this, _port, _virtualPath, _physicalPath, _requireAuthentication, _disableDirectoryListing); _host = host; } } finally { if (flag) { Monitor.Exit(obj2); } } #else lock (_lockObject) { host = _host; if (host == null) { host = (Host)CreateWorkerAppDomainWithHost(_virtualPath, _physicalPath, typeof(Host)); host.Configure(this, _port, _virtualPath, _physicalPath, _requireAuthentication, _disableDirectoryListing); _host = host; } } #endif } return(host); }
public void Create_And_Configure_Host() { var server = new Server("_temp_CassiniSite".tempDir()); var host = new Host(); Assert.IsNotNull(host); //check values before configure Assert.Throws<NullReferenceException>(()=> host.GetProcessToken()); Assert.Throws<NullReferenceException>(()=> host.GetProcessUser()); Assert.IsNotNull(host.AppDomain); Assert.IsFalse (host.DisableDirectoryListing); Assert.IsNull (host.NormalizedClientScriptPath); Assert.IsNull (host.NormalizedVirtualPath); Assert.IsNull (host.PhysicalClientScriptPath); Assert.IsNull (host.PhysicalPath); Assert.AreEqual (0, host.Port); Assert.IsFalse (host.RequireAuthentication); Assert.IsNull (host.VirtualPath); host.Configure(server, server.Port, server.VirtualPath, server.PhysicalPath); //check values after configure Assert.AreNotEqual(host.GetProcessToken(),IntPtr.Zero); Assert.IsNotNull (host.GetProcessUser()); Assert.IsFalse (host.DisableDirectoryListing); Assert.IsNull (host.InstallPath); Assert.IsNotNull (host.NormalizedClientScriptPath); Assert.IsNotNull (host.NormalizedVirtualPath); Assert.IsNotNull (host.PhysicalClientScriptPath); Assert.IsNotNull (host.PhysicalPath); Assert.AreNotEqual(0, host.Port); Assert.IsFalse(host.RequireAuthentication); Assert.IsNotNull (host.VirtualPath); //removed tempDir server.PhysicalPath.delete_Folder(); }
private Host CreateHost(string physicalPath, string virtualPath) { Host host = new Host(); host.Configure(this, Server.Port, virtualPath, physicalPath, Server.RequireAuthentication, Server.DisableDirectoryListing); var output = new KeepAliveTextWriter(OutputWriter ?? Console.Out); var applicationManager = ApplicationManager.GetApplicationManager(); host = CreateWorkerAppDomainWithHost(host); host.SetConsoleOut(output); if (HostCreated != null) { HostCreated.Invoke(this, new HostCreatedEventArgs(virtualPath, physicalPath)); } Console.WriteLine("Host created {0}", virtualPath); return(host); }
/// <summary> /// /// </summary> /// <param name="virtualPath"></param> /// <param name="physicalPath"></param> /// <param name="hostType"></param> /// <param name="port"></param> /// <returns></returns> /// <remarks> /// This is Dmitry's hack to enable running outside of GAC. /// There are some errors being thrown when running in proc /// </remarks> private Host CreateWorkerAppDomainWithHost(Host host) { // create BuildManagerHost in the worker app domain Type buildManagerHostType = typeof(HttpRuntime).Assembly.GetType("System.Web.Compilation.BuildManagerHost"); IRegisteredObject buildManagerHost = ApplicationManager.GetObject(host.GetSiteID(), buildManagerHostType); if (buildManagerHost == null) { buildManagerHost = ApplicationManager.CreateObject(host, buildManagerHostType); } // call BuildManagerHost.RegisterAssembly to make Host type loadable in the worker app domain buildManagerHostType.InvokeMember("RegisterAssembly", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, buildManagerHost, new object[] { host.GetType().Assembly.FullName, host.GetType().Assembly.Location }); // create Host in the worker app domain // FIXME: getting FileLoadException Could not load file or assembly 'WebDev.WebServer20, Version=4.0.1.6, Culture=neutral, PublicKeyToken=f7f6e0b4240c7c27' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418) // when running dnoa 3.4 samples - webdev is registering trust somewhere that we are not Console.WriteLine("Creating Worker AppDomain {0}", host.GetSiteID()); Host remoteHost = (Host)ApplicationManager.GetObject(host.GetSiteID(), host.GetType()); if (remoteHost == null) { remoteHost = (Host)ApplicationManager.CreateObject(host, host.GetType()); } remoteHost.Configure(this, host.Port, host.VirtualPath, host.PhysicalPath, host.RequireAuthentication, host.DisableDirectoryListing); return(remoteHost); }