//		private bool _headersSent;

		/// <summary>
		/// Initializes a new instance of the AspWorkerRequest class
		/// </summary>
		/// <param name="connection"></param>
		/// <param name="request"></param>
		public AspWorkerRequest(AspHost aspHost, HttpConnection connection, HttpRequest request) : base(string.Empty, string.Empty, null)
		{						
			_aspHost = aspHost;
			_connection = connection;
			_request = request;
			_response = new HttpResponse(new OkStatus());

			this.ParsePathInfo();
		}
示例#2
0
//		private bool _headersSent;

        /// <summary>
        /// Initializes a new instance of the AspWorkerRequest class
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="request"></param>
        public AspWorkerRequest(AspHost aspHost, HttpConnection connection, HttpRequest request) : base(string.Empty, string.Empty, null)
        {
            _aspHost    = aspHost;
            _connection = connection;
            _request    = request;
            _response   = new HttpResponse(new OkStatus());

            this.ParsePathInfo();
        }
		/// <summary>
		/// Creates an internal AspHost instance to allow the dispatcher to send requests off to the HttpRuntime
		/// </summary>
		internal void CreateAspHost()
		{
			try
			{
				string physicalDirectory = Application.StartupPath; // Path.Combine(Application.StartupPath, @"wwwroot");
				string configurationFile = Path.Combine(physicalDirectory, @"web.config");

				_aspHost = AspRuntime.CreateAspHost(@"/", physicalDirectory, string.Empty, configurationFile);
			}
			catch(Exception ex)
			{
				Debug.WriteLine(ex);
			}
		}
        /// <summary>
        /// Creates and initializes a new AspHost instance on it's own AppDomain
        /// </summary>
        /// <param name="virtualDirectory"></param>
        /// <param name="physicalDirectory"></param>
        /// <param name="applicationBaseDirectory"></param>
        /// <param name="configurationFile"></param>
        /// <returns></returns>
        public static AspHost CreateAspHost(
            string virtualDirectory,
            string physicalDirectory,
            string applicationBaseDirectory,
            string configurationFile)
        {
            if (!physicalDirectory.EndsWith("\\"))
            {
                physicalDirectory += "\\";
            }

            string         domainId       = string.Format("AspHost_{0}", DateTime.Now.ToString().GetHashCode().ToString("x"));
            string         appName        = (virtualDirectory + physicalDirectory).GetHashCode().ToString("x");
            AppDomainSetup appDomainSetup = new AppDomainSetup();

            appDomainSetup.ApplicationName   = appName;
            appDomainSetup.ConfigurationFile = configurationFile;
            if (!HttpUtils.IsEmptryString(applicationBaseDirectory) && !HttpUtils.IsNullString(applicationBaseDirectory))
            {
                appDomainSetup.ApplicationBase = applicationBaseDirectory;
            }

            AppDomain appDomain = AppDomain.CreateDomain(domainId, null, appDomainSetup);

            appDomain.SetData(@".appDomain", @"*");
            appDomain.SetData(@".appPath", physicalDirectory);
            appDomain.SetData(@".appVPath", virtualDirectory);
            appDomain.SetData(@".domainId", domainId);
            appDomain.SetData(@".hostingVirtualPath", virtualDirectory);
            appDomain.SetData(@".hostingInstallDir", HttpRuntime.AspInstallDirectory);

            Debug.WriteLine(string.Format("Creating 'AspHost' for requests in '{0}' mapped to '{1}'", virtualDirectory, physicalDirectory), "'AspRuntime'");

            ObjectHandle hInstance = appDomain.CreateInstance(typeof(AspHost).Module.Assembly.FullName, typeof(AspHost).FullName);
            AspHost      host      = (AspHost)hInstance.Unwrap();

            host.VirtualDirectory  = virtualDirectory;
            host.PhysicalDirectory = physicalDirectory;
            host.AppDomain         = appDomain;

            return(host);
        }
		protected virtual void Dispose(bool disposing)
		{
			if (_disposed)
			{
				if (disposing)
				{
					if (_aspHost != null)
					{
						_aspHost.Dispose();
						_aspHost = null;
					}
				}
				_disposed = true;
			}
		}