public void Context_BeginRequest(object sender, EventArgs e) { if (Interlocked.Exchange(ref _isInitialRequest, 0) != 1) { return; } if (!CurrentPortMatchesDeleporterSetting((HttpApplication)sender) || RemotingChannelExists()) { return; } if (WasCompiledInDebugMode(sender)) { // Start listening for connections RemotingConfiguration.RegisterWellKnownServiceType(typeof(DeleporterService), DeleporterConfiguration.ServiceName, WellKnownObjectMode.Singleton); this._remotingChannel = DeleporterConfiguration.CreateChannel(); LoggerServer.Log("Registering remoting channel on port {0}", DeleporterConfiguration.RemotingPort); ChannelServices.RegisterChannel(this._remotingChannel, false); } else { var thisAssembly = Assembly.GetExecutingAssembly().GetName(); throw new InvalidOperationException( string.Format("You should not enable Deleporter on production web servers. As a security precaution, Deleporter won't run if your ASP.NET application was compiled in Release mode. You need to remove DeleporterServerModule from your Web.config file. If you need to bypass this, the only way is to edit the Deleporter source code and remove this check. Assembly name {0} Version {1}", thisAssembly.Name, thisAssembly.Version)); } }
/// <summary> /// Depending on the test runner, it is possible that tests may be aborted without proper cleanup. Ports may be left unavailable for a while. Work around this by getting fresh ports if needed. /// </summary> public static void SetWebAndRemotingPortsBasedOnAvailability() { var webHostPort = FindNextAvailablePort(DeleporterConfiguration.WebHostPort); var remotingPort = FindNextAvailablePort(DeleporterConfiguration.RemotingPort); if (webHostPort != DeleporterConfiguration.WebHostPort || remotingPort != DeleporterConfiguration.RemotingPort) { DeleporterConfiguration.UpdatePortsInWebConfig(webHostPort, remotingPort); } }