/// <summary>
        /// Processes a script and returns the result as a string.
        /// </summary>
        /// <param name="Page">Name of the page to return</param>
        /// <param name="QueryString">Optional query string</param>
        /// <returns>script result or null on failure. Script errors are returned as errors in the script result string.</returns>
        public virtual string ProcessRequestToString(string Page, string QueryString)
        {
            StringWriter sw     = new StringWriter();
            TextWriter   Writer = new System.Web.UI.HtmlTextWriter(sw);

            // *** Reset the Response settings
            this.ResponseHeaders    = null;
            this.Cookies            = null;
            this.ResponseStatusCode = 200;

            wwWorkerRequest Request = new wwWorkerRequest(Page, QueryString, Writer);

            if (this.Context != null)
            {
                Request.Context = this.Context;
            }

            Request.PostData        = this.PostData;
            Request.PostContentType = this.PostContentType;
            Request.RequestHeaders  = this.RequestHeaders;
            Request.PhysicalPath    = this.PhysicalDirectory;

            try
            {
                HttpRuntime.ProcessRequest(Request);
            }
            catch (Exception ex)
            {
                this.ResponseStatusCode = Request.ResponseStatusCode;
                this.ErrorMessage       = ex.Message;
                this.Error = true;
                return(null);
            }

            string Result = sw.ToString();

            Writer.Close();

            this.ResponseHeaders    = Request.ResponseHeaders;
            this.ResponseStatusCode = Request.ResponseStatusCode;

            this.Cookies = Request.Cookies;
            this.Context = Request.Context;

            return(Result);
        }
        /// <summary>
        /// Processes script execution on the specified page.
        /// </summary>
        /// <param name="Page">A page filename relative to the Virtual directory. Use subdir\sub2\test.aspx style syntax for subdirs. (note forward slash!)</param>
        /// <param name="QueryString">Optional - query string in key value pair format. Pass null for non.</param>
        /// <returns>true or false. False returns only if a real failure occurs - most page errors will result in an HTTP error page.</returns>
        public virtual bool ProcessRequest(string Page, string QueryString)
        {
            TextWriter Output;

            try
            {
                // *** Note you have to write the right 'codepage'. If you use the default UTF-8
                // *** everything will be double encoded.
                Output = new StreamWriter(this.OutputFile, false, Encoding.GetEncoding(1252));

                // *** Write the UTF-8 prefix
                Output.Write("");
            }
            catch (Exception ex)
            {
                this.Error        = true;
                this.ErrorMessage = ex.Message;
                return(false);
            }

            // *** Reset the Response settings
            this.ResponseHeaders    = null;
            this.Cookies            = null;
            this.ResponseStatusCode = 200;

            wwWorkerRequest Request = new wwWorkerRequest(Page, QueryString, Output);

            if (this.Context != null)
            {
                Request.Context = this.Context;
            }

            Request.PostData        = this.PostData;
            Request.PostContentType = this.PostContentType;
            Request.RequestHeaders  = this.RequestHeaders;
            Request.PhysicalPath    = this.PhysicalDirectory;

            try
            {
                HttpRuntime.ProcessRequest(Request);
            }
            catch (Exception ex)
            {
                Output.Close();
                this.ResponseStatusCode = 500;
                this.ErrorMessage       = ex.Message;
                this.Error = true;
                return(false);
            }

            Output.Close();

            this.ResponseHeaders    = Request.ResponseHeaders;
            this.ResponseStatusCode = Request.ResponseStatusCode;


            // *** Capture the Cookies that were set by the server
            this.Cookies = Request.Cookies;

            if (Request.Context != null)
            {
                this.Context = Request.Context;
            }

            return(true);
        }