Beispiel #1
0
        public void Process()
        {
            if (!TryParseRequest())
            {
                return;
            }

            if (ResponseHeader.Method == "POST" && _contentLength > 0 && _preloadedContentLength < _contentLength)
            {
                Session.Write100Continue();
            }
            if (!Host.RequireAuthentication || TryNtlmAuthenticate())
            {
                if (_isClientScriptPath)
                {
                    Session.WriteEntireResponseFromFile(Host.PhysicalClientScriptPath + _path.Substring(Host.NormalizedClientScriptPath.Length), false);
                }
                else if (IsRequestForRestrictedDirectory())
                {
                    Session.WriteErrorAndClose(403);
                }
                else if (!ProcessDefaultDocumentRequest())
                {
                    PrepareResponse();
                    HttpRuntime.ProcessRequest(this);
                }
            }
        }
Beispiel #2
0
        public void ProcessRequest(String page, string soapmsg, string soapAction)
        {
            HttpWorkerRequest hwr =
                new SoapWorkerRequest(page, soapmsg, soapAction, Console.Out);

            HttpRuntime.ProcessRequest(hwr);
        }
Beispiel #3
0
                                  public bool ProcessRequest(
//string appVirtualDir_in,
//string appPhysicalDir_in,
                                      string aspxFile_in,
                                      string parameters_in,
                                      TextWriter textwriter_in
                                      )
                                  {
                                      _aux_SimpleWorkerRequest _simpleworkerrequest =
                                          new _aux_SimpleWorkerRequest(
//appVirtualDir_in,
//appPhysicalDir_in,
                                              aspxFile_in,
                                              parameters_in,
                                              textwriter_in
                                              );

                                      HttpRuntime.ProcessRequest(
                                          _simpleworkerrequest
                                          );
                                      if (
                                          (_simpleworkerrequest.Server != null)
                                          &&
                                          (_simpleworkerrequest.Server.GetLastError() != null)
                                          )
                                      {
                                          _simpleworkerrequest.Server.ClearError();
                                          return(false);
                                      }
                                      return(true);
                                  }
        /*
         * Process one ISAPI request
         *
         * @param ecb ECB
         * @param useProcessModel flag set to true when out-of-process
         */
        /// <include file='doc\ISAPIRuntime.uex' path='docs/doc[@for="ISAPIRuntime.ProcessRequest"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public int ProcessRequest(IntPtr ecb, int iWRType)
        {
            HttpWorkerRequest wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, iWRType);
//              switch (iWRType) {
//                  case 2:
//                      wr = new IEWorkerRequest(ecb);
//                      break;
//                  default:
//                      wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, iWRType);
//              break;
//              }

            // check if app path matches (need to restart app domain?)

            String wrPath = wr.GetAppPathTranslated();
            String adPath = HttpRuntime.AppDomainAppPathInternal;


            if (adPath == null || wrPath.Equals(".") ||  // for xsptool it is '.'
                String.Compare(wrPath, adPath, true, CultureInfo.InvariantCulture) == 0)
            {
                HttpRuntime.ProcessRequest(wr);
                return(0);
            }
            else
            {
                // need to restart app domain
                HttpRuntime.ShutdownAppDomain("Physical application path changed from " + adPath + " to " + wrPath);
                return(1);
            }
        }
Beispiel #5
0
		public void ProcessRequest()
		{
			HttpListenerContext ctx = _listener.GetContext();
			HttpListenerWorkerRequest workerRequest =
				new HttpListenerWorkerRequest(ctx, _virtualDir, _physicalDir);
			HttpRuntime.ProcessRequest(workerRequest);
		}
Beispiel #6
0
 public void ProcessRequest(IAspNetWorker aspNetWorkerRequest)
 {
     //TODO: Find a way to prevent the IAspNetWorkerRequest implementation
     //from also having to be a HttpWorkerRequest. Perhaps some type of a
     //proxy object.
     HttpRuntime.ProcessRequest((HttpWorkerRequest)aspNetWorkerRequest);
 }
Beispiel #7
0
        public void ProcessRequest(AspRequestData req)
        {
            this._reqData = req;
            string s    = "";
            bool   flag = false;

            try
            {
                HttpRuntime.ProcessRequest(this);
            }
            catch (HttpException exception)
            {
                flag = true;
                s    = exception.GetHtmlErrorMessage();
            }
            catch (Exception exception2)
            {
                flag = true;
                s    = new HttpException(400, "Bad request", exception2).GetHtmlErrorMessage();
            }
            if (flag)
            {
                this.SendStatus(400, "Bad request");
                this.SendUnknownResponseHeader("Connection", "close");
                this.SendUnknownResponseHeader("Date", DateTime.Now.ToUniversalTime().ToString("r"));
                Encoding encoding = Encoding.UTF8;
                byte[]   bytes    = encoding.GetBytes(s);
                this.SendUnknownResponseHeader("Content-Type", "text/html; charset=" + encoding.WebName);
                this.SendUnknownResponseHeader("Content-Length", bytes.Length.ToString());
                this._keepAlive = false;
                this.SendResponseFromMemory(bytes, bytes.Length);
                this.FlushResponse(true);
            }
        }
Beispiel #8
0
        static Task RunArbitraryFn(CancellationToken cancel, FnInner fn)
        {
            var tcs = new TaskCompletionSource <bool>();

            try
            {
                var thread = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        _context = new FakeAspContext(tcs, fn, cancel);
                        HttpRuntime.ProcessRequest(new SimpleWorkerRequest("", "", new StringWriter()));
                    }
                    catch (Exception ex)
                    {
                        tcs.TrySetException(ex);
                    }
                }));

                thread.Start();

                cancel.Register(() =>
                {
                    thread.Abort();
                    tcs.TrySetException(new Exception("Cancelled!"));
                });
            }
            catch (Exception ex)
            {
                tcs.TrySetException(ex);
            }

            return(tcs.Task);
        }
        /// <summary>
        /// 获取本地页面内容
        /// </summary>
        /// <param name="templatePath"></param>
        /// <param name="query"></param>
        /// <param name="encoding"></param>
        /// <param name="validateString"></param>
        /// <returns></returns>
        internal static string GetLocalPageString(string templatePath, string query, Encoding encoding, string validateString)
        {
            StringBuilder sb = new StringBuilder();

            using (StringWriter sw = new StringWriter(sb))
            {
                try
                {
                    var page = templatePath.Replace("/", "\\").TrimStart('\\');
                    HttpRuntime.ProcessRequest(new EncodingWorkerRequest(page, query, sw, encoding));
                }
                catch (ThreadAbortException)
                {
                    //线程异常,则跳过
                }
            }

            string content = sb.ToString();

            //验证字符串
            if (string.IsNullOrEmpty(validateString))
            {
                throw new WebException("执行本地页面" + templatePath + (query == null ? "" : "?" + query) + "出错,验证字符串不能为空。");
            }
            else if (content.IndexOf(validateString) < 0)
            {
                throw new WebException("执行本地页面" + templatePath + (query == null ? "" : "?" + query) + "出错,页面内容和验证字符串匹配失败。");
            }

            return(content);
        }
Beispiel #10
0
        public Task Invoke(IDictionary <string, object> environment)
        {
            var workerRequest = new KatanaWorkerRequest(environment);

            HttpRuntime.ProcessRequest(workerRequest);
            return(workerRequest.Completed);
        }
Beispiel #11
0
        public void Process() {
            // read the request
            if (!TryParseRequest()) {
                return;
            }

            // 100 response to POST
            if (_verb == "POST" && _contentLength > 0 && _preloadedContentLength < _contentLength) {
                _connection.Write100Continue();
            }

            // special case for client script
            if (_isClientScriptPath) {
                _connection.WriteEntireResponseFromFile(_host.PhysicalClientScriptPath + _path.Substring(_host.NormalizedClientScriptPath.Length), false);
                return;
            }

            // deny access to code, bin, etc.
            if (IsRequestForRestrictedDirectory()) {
                _connection.WriteErrorAndClose(403);
                return;
            }

            // special case for a request to a directory (ensure / at the end and process default documents)
            if (ProcessDirectoryRequest()) {
                return;
            }

            PrepareResponse();

            // Hand the processing over to HttpRuntime
            HttpRuntime.ProcessRequest(this);
        }
Beispiel #12
0
        void AsyncRun(object param)
        {
            for (;;)
            {
                _doNext.WaitOne();
                try {
                    WebTest           t    = _currentTest;
                    HttpWorkerRequest wr   = t.Request.CreateWorkerRequest();
                    MyData            data = GetMyData(wr);
                    data.currentTest = t;
                    data.exception   = null;

                    HttpRuntime.ProcessRequest(wr);
                    t.Response = t.Request.ExtractResponse(wr);

                    if (data.exception != null)
                    {
                        RethrowException(data.exception);
                    }
                } catch (Exception e) {
                    _e = e;
                }

                _done.Set();
            }
        }
Beispiel #13
0
        // GET: Pipe
        public ActionResult Index()
        {
            HttpRuntime.ProcessRequest(null);
            //HttpApplicationFactory

            return(View());
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            // Create the application host
            object host = ApplicationHost.CreateApplicationHost(typeof(MyHost), "/", "c:\\");

            int request_count = 10;

            SimpleWorkerRequest [] requests = new SimpleWorkerRequest[request_count];

            int pos;

            for (pos = 0; pos != request_count; pos++)
            {
                requests[pos] = new SimpleWorkerRequest("test.aspx", "", Console.Out);
            }

            ModulesConfiguration.Add("syncmodule", typeof(SyncModule).AssemblyQualifiedName);
            ModulesConfiguration.Add("asyncmodule", typeof(AsyncModule).AssemblyQualifiedName);

            HandlerFactoryConfiguration.Add("get", "/", typeof(AsyncHandler).AssemblyQualifiedName);
            //HandlerFactoryConfiguration.Add("get", "/", typeof(SyncHandler).AssemblyQualifiedName);

            for (pos = 0; pos != request_count; pos++)
            {
                HttpRuntime.ProcessRequest(requests[pos]);
            }

            HttpRuntime.Close();

/*
 *                      Console.Write("Press Enter to quit.");
 *                      Console.WriteLine();
 *                      Console.ReadLine();
 */
        }
Beispiel #15
0
        private void ProcessRequest()
        {
            HttpListenerContext ctx;

            try
            {
                ctx = _listener.GetContext();
            }
            catch (HttpListenerException)
            {
                return;
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                return;
            }
            QueueNextRequestWait();
            var workerRequest = new HttpListenerWorkerRequest(ctx, _virtualDir, _physicalDir);

            try
            {
                HttpRuntime.ProcessRequest(workerRequest);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
        }
Beispiel #16
0
    public void Execute(string page)
    {
        SimpleWorkerRequest req = new SimpleWorkerRequest(
            page, "", Console.Out);

        HttpRuntime.ProcessRequest(req);
    }
        public string Render_SimpleWorkerRequest(SimpleWorkerRequest simpleWorkerRequest, StringWriter stringWriter)
        {
            HttpRuntime.ProcessRequest(simpleWorkerRequest);
            var response = stringWriter.ToString();

            return(response);
        }
Beispiel #18
0
        public Response Process(Request request, Action <Request> modifier = null)
        {
            if (modifier != null)
            {
                modifier(request);
            }

            using (var output = new StringWriter())
            {
                CaptureResultFilter.LastResult = null;

                var workerRequest = new SimulatedWorkerRequest(request, Cookies, output);
                HttpRuntime.ProcessRequest(workerRequest);

                var responseText = output.ToString();
                LastResponseText = responseText;

                var response = new Response
                {
                    RequestUrl        = request.OriginalUrl,
                    StatusCode        = workerRequest.StatusCode,
                    StatusDescription = workerRequest.StatusDescription,
                    Text       = responseText,
                    LastResult = CaptureResultFilter.LastResult,
                };

                if (request.ExptectedResponse.HasValue && request.ExptectedResponse.Value != response.HttpStatusCode)
                {
                    throw new UnexpectedStatusCodeException(response, request.ExptectedResponse.Value);
                }

                return(response);
            }
        }
        /// <summary>
        /// 异步处理请求
        /// </summary>
        /// <param name="context"></param>
        private void Request(HttpListenerContext context)
        {
            HttpListenerWorkerRequest workerRequest =
                new HttpListenerWorkerRequest(context, _virtualDir, _physicalDir);

            HttpRuntime.ProcessRequest(workerRequest);
        }
        public RequestRespose RunRequest(Uri url, string httpVerbName, byte[] data, NameValueCollection headers)
        {
            HostProxyWorkerRequest request = null;
            string responseContent         = null;

            using (var output = new StringWriter())
            {
                var cookies = CreateRequestCookies(headers);
                request = new HostProxyWorkerRequest(url, output, cookies, httpVerbName, data, headers);
                HttpRuntime.ProcessRequest(request);
                responseContent = output.ToString();
            }

            var responseHeaders = request.HttpContext.CreateResponseHeaders();
            var responseCookies = request.HttpContext.CreateResponseCookies();

            return(new RequestRespose
            {
                Content = responseContent,
                StatusCode = request.HttpContext.Response.StatusCode,
                Headers = responseHeaders,
                ContentType = request.HttpContext.Response.ContentType,
                Cookies = responseCookies
            });
        }
Beispiel #21
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Process(ReBugContext context)
        {
            ErrorModule.IsReBug = true;
            HttpWorkerRequest swr = new BugxWorkerRequest(context, Console.Out);

            HttpRuntime.ProcessRequest(swr);
        }
Beispiel #22
0
 public void Process()
 {
     if (!this.TryParseRequest())
     {
         return;
     }
     if (this._verb == "POST" && this._contentLength > 0 && this._preloadedContentLength < this._contentLength)
     {
         this._connection.Write100Continue();
     }
     if (this._host.RequireAuthentication && !this.TryNtlmAuthenticate())
     {
         return;
     }
     if (this._isClientScriptPath)
     {
         this._connection.WriteEntireResponseFromFile(this._host.PhysicalClientScriptPath + this._path.Substring(this._host.NormalizedClientScriptPath.Length), false);
         return;
     }
     if (this.IsRequestForRestrictedDirectory())
     {
         this._connection.WriteErrorAndClose(403);
         return;
     }
     if (this.ProcessDefaultDocumentRequest())
     {
         return;
     }
     this.PrepareResponse();
     HttpRuntime.ProcessRequest(this);
 }
Beispiel #23
0
        public RequestResult ProcessRequest(Uri uri, string httpVerb, string formValues, NameValueCollection headers)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("url");
            }

            // Perform the request
            LastRequestData.Reset();
            var output = new StringWriter();

            httpVerb = (httpVerb ?? "GET").ToUpper();
            var workerRequest = new SimulatedWorkerRequest(uri, output, Cookies, httpVerb, formValues, headers);
            var ctx           = HttpContext.Current = new HttpContext(workerRequest);

            HttpRuntime.ProcessRequest(workerRequest);
            var response = LastRequestData.Response ?? ctx.Response;

            // Capture the output
            AddAnyNewCookiesToCookieCollection(response);
            Session = ctx.Session;
            return(new RequestResult {
                ResponseText = output.ToString(),
                ActionExecutedContext = LastRequestData.ActionExecutedContext,
                ResultExecutedContext = LastRequestData.ResultExecutedContext,
                Response = response,
            });
        }
        public void ProcessRequest()
        {
            string error = null;

            _inUnhandledException = false;

            try
            {
                //System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace();
                //byte[] b = Encoding.GetBytes("Here's the trace: <br /><br />" + t.ToString());
                //_worker.Write(b, 0, b.Length);

                //AssertFileAccessible();
                HttpRuntime.ProcessRequest(this);
            }
            catch (HttpException ex)
            {
                _inUnhandledException = true;
                error = ex.GetHtmlErrorMessage();
            }
            catch (Exception ex)
            {
                _inUnhandledException = true;
                var hex = new HttpException(400, "Bad request", ex);
                error = hex.GetHtmlErrorMessage();
            }

            if (!_inUnhandledException)
            {
                return;
            }

            //error = "HELLLO FROM WebFormsWorkerRequest";

            if (error.Length == 0)
            {
                error = String.Format("<html><head><title>Runtime Error</title></head><body>An exception ocurred:<pre>{0}</pre></body></html>", "Unknown error");
            }

            try
            {
                SendStatus(400, "Bad request");
                SendUnknownResponseHeader("Connection", "close");
                SendUnknownResponseHeader("Date", DateTime.Now.ToUniversalTime().ToString("r"));

                Encoding enc = Encoding.UTF8;

                byte[] bytes = enc.GetBytes(error);

                SendUnknownResponseHeader("Content-Type", "text/html; charset=" + enc.WebName);
                SendUnknownResponseHeader("Content-Length", bytes.Length.ToString());
                SendResponseFromMemory(bytes, bytes.Length);
                FlushResponse(true);
            }
            catch (Exception)
            { // should "never" happen
                throw;
            }
        }
Beispiel #25
0
        public RequestResult ProcessRequest(string url, HttpVerbs httpVerb, NameValueCollection formValues, NameValueCollection headers)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            if (httpVerb == HttpVerbs.Post && headers == null)
            {
                headers = new NameValueCollection();
                headers.Add("content-type", "application/x-www-form-urlencoded");
            }
            else if (httpVerb == HttpVerbs.Post && headers != null)
            {
                if (string.IsNullOrEmpty(headers["content-type"]))
                {
                    headers.Add("content-type", "application/x-www-form-urlencoded");
                }
            }

            // Fix up URLs that incorrectly start with / or ~/
            if (url.StartsWith("~/"))
            {
                url = url.Substring(2);
            }
            else if (url.StartsWith("/"))
            {
                url = url.Substring(1);
            }

            // Parse out the querystring if provided
            string query = "";
            int    querySeparatorIndex = url.IndexOf("?");

            if (querySeparatorIndex >= 0)
            {
                query = url.Substring(querySeparatorIndex + 1);
                url   = url.Substring(0, querySeparatorIndex);
            }

            // Perform the request
            LastRequestData.Reset();
            var    output        = new StringWriter();
            string httpVerbName  = httpVerb.ToString().ToLower();
            var    workerRequest = new SimulatedWorkerRequest(url, query, output, Cookies, httpVerbName, formValues, headers);

            HttpRuntime.ProcessRequest(workerRequest);

            // Capture the output
            AddAnyNewCookiesToCookieCollection();
            Session = LastRequestData.HttpSessionState;
            return(new RequestResult
            {
                ResponseText = output.ToString(),
                ActionExecutedContext = LastRequestData.ActionExecutedContext,
                ResultExecutedContext = LastRequestData.ResultExecutedContext,
                Response = LastRequestData.Response,
            });
        }
Beispiel #26
0
        public bool ProcessRequest(IHttpContext context)
        {
            var workerRequest = new AspServerRequest(context, this.VirtualPath, this.PhysicalPath);

            HttpRuntime.ProcessRequest(workerRequest);

            return(true);
        }
Beispiel #27
0
        public void Go(string hostname, string page, string queryString)
        {
            var sw = new StringWriter();
            var wr = new SimpleWorkerRequest(page, queryString, sw);

            // This causes ASP.NET to process the request
            HttpRuntime.ProcessRequest(wr);
        }
Beispiel #28
0
        /// <summary>
        /// </summary>
        /// <param name="filename">
        /// </param>
        /// <param name="queryString">
        /// </param>
        /// <returns>
        /// </returns>
        private string ProcessFile(string filename, string queryString)
        {
            var sw           = new StringWriter();
            var simpleWorker = new SimpleWorkerRequest(filename, queryString, sw);

            HttpRuntime.ProcessRequest(simpleWorker);
            return(sw.ToString());
        }
Beispiel #29
0
        public void ProcessRequest(string page)
        {
            StreamWriter writer = new StreamWriter(@"C:\Inetpub\wwwroot\TestAspnetHost\temp.htm", false, Encoding.GetEncoding("gb2312"));

            HttpRuntime.ProcessRequest(new SimpleWorkerRequest(page, null, writer));
            writer.Flush();
            writer.Close();
        }
Beispiel #30
0
        public void Process()
        {
            ReadAllHeaders();

            if (_headerBytes == null || _endHeadersOffset < 0 ||
                _headerByteStrings == null || _headerByteStrings.Count == 0)
            {
                _conn.WriteErrorAndClose(400);
                return;
            }

            ParseRequestLine();

            // Check for bad path
            if (IsBadPath())
            {
                _conn.WriteErrorAndClose(400);
                return;
            }

            // Check if the path is not well formed or is not for the current app
            bool   isClientScriptPath = false;
            String clientScript       = null;

            if (!_host.IsVirtualPathInApp(_path, out isClientScriptPath, out clientScript))
            {
                _conn.WriteErrorAndClose(404);
                return;
            }

            ParseHeaders();

            ParsePostedContent();

            if (_verb == "POST" && _contentLength > 0 && _preloadedContentLength < _contentLength)
            {
                _conn.Write100Continue();
            }

            // special case for client script
            if (isClientScriptPath)
            {
                _conn.WriteEntireResponseFromFile(_host.PhysicalClientScriptPath + clientScript, false);
                return;
            }

            // special case for directory listing
            if (ProcessDirectoryListingRequest())
            {
                return;
            }

            PrepareResponse();

            // Hand the processing over to HttpRuntime

            HttpRuntime.ProcessRequest(this);
        }