Esempio n. 1
0
        /// <summary>
        /// Sets up the HttpContext objects to simulate a request.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="httpVerb"></param>
        /// <param name="formVariables"></param>
        /// <param name="headers"></param>
        protected virtual HttpSimulator SimulateRequest(Uri url, HttpVerb httpVerb, NameValueCollection formVariables, NameValueCollection headers)
        {
            HttpContext.Current = null;

            ParseRequestUrl(url);

            if (ResponseWriter == null)
            {
                _builder       = new StringBuilder();
                ResponseWriter = new StringWriter(_builder);
            }

            SetHttpRuntimeInternals();

            var query = ExtractQueryStringPart(url);

            if (formVariables != null)
            {
                _formVars.Add(formVariables);
            }

            if (_formVars.Count > 0)
            {
                httpVerb = HttpVerb.POST; //Need to enforce this.
            }
            if (headers != null)
            {
                _headers.Add(headers);
            }

            WorkerRequest = new SimulatedHttpRequest(ApplicationPath, PhysicalApplicationPath, PhysicalPath, Page, query, ResponseWriter, Host, Port, httpVerb.ToString());

            WorkerRequest.Form.Add(_formVars);
            WorkerRequest.Headers.Add(_headers);

            if (_referer != null)
            {
                WorkerRequest.SetReferer(_referer);
            }

            InitializeSession();

            InitializeApplication();

            #region Console Debug INfo

            //Console.WriteLine("host: " + Host);
            //Console.WriteLine("virtualDir: " + _applicationPath);
            //Console.WriteLine("page: " + LocalPath);
            //Console.WriteLine("pathPartAfterApplicationPart: " + Page);
            //Console.WriteLine("appPhysicalDir: " + _physicalApplicationPath);
            //if (HttpContext.Current != null)
            //{
            //    Console.WriteLine("Request.Url.LocalPath: " + HttpContext.Current.Request.Url.LocalPath);
            //    Console.WriteLine("Request.Url.Host: " + HttpContext.Current.Request.Url.Host);
            //    Console.WriteLine("Request.FilePath: " + HttpContext.Current.Request.FilePath);
            //    Console.WriteLine("Request.Path: " + HttpContext.Current.Request.Path);
            //    Console.WriteLine("Request.RawUrl: " + HttpContext.Current.Request.RawUrl);
            //    Console.WriteLine("Request.Url: " + HttpContext.Current.Request.Url);
            //    Console.WriteLine("Request.Url.Port: " + HttpContext.Current.Request.Url.Port);
            //    Console.WriteLine("Request.ApplicationPath: " + HttpContext.Current.Request.ApplicationPath);
            //    Console.WriteLine("Request.PhysicalPath: " + HttpContext.Current.Request.PhysicalPath);
            //}
            //Console.WriteLine("HttpRuntime.AppDomainAppPath: " + HttpRuntime.AppDomainAppPath);
            //Console.WriteLine("HttpRuntime.AppDomainAppVirtualPath: " + HttpRuntime.AppDomainAppVirtualPath);
            //Console.WriteLine("HostingEnvironment.ApplicationPhysicalPath: " + HostingEnvironment.ApplicationPhysicalPath);
            //Console.WriteLine("HostingEnvironment.ApplicationVirtualPath: " + HostingEnvironment.ApplicationVirtualPath);

            #endregion

            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets up the HttpContext objects to simulate a request.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="httpVerb"></param>
        /// <param name="formVariables"></param>
        /// <param name="headers"></param>
        protected virtual HttpSimulator SimulateRequest(Uri url, HttpVerb httpVerb, NameValueCollection formVariables, NameValueCollection headers)
        {
            HttpContext.Current = null;

            ParseRequestUrl(url);

            if (ResponseWriter == null)
            {
                _builder = new StringBuilder();
                ResponseWriter = new StringWriter(_builder);
            }

            SetHttpRuntimeInternals();

            var query = ExtractQueryStringPart(url);

            if (formVariables != null)
                _formVars.Add(formVariables);

            if (_formVars.Count > 0)
                httpVerb = HttpVerb.POST; //Need to enforce this.

            if (headers != null)
                _headers.Add(headers);

            WorkerRequest = new SimulatedHttpRequest(ApplicationPath, PhysicalApplicationPath, PhysicalPath, Page, query, ResponseWriter, Host, Port, httpVerb.ToString());

            WorkerRequest.Form.Add(_formVars);
            WorkerRequest.Headers.Add(_headers);

            if (_referer != null)
                WorkerRequest.SetReferer(_referer);

        	InitializeSession();

			InitializeApplication();
            
            #region Console Debug INfo

            //Console.WriteLine("host: " + Host);
            //Console.WriteLine("virtualDir: " + _applicationPath);
            //Console.WriteLine("page: " + LocalPath);
            //Console.WriteLine("pathPartAfterApplicationPart: " + Page);
            //Console.WriteLine("appPhysicalDir: " + _physicalApplicationPath);
            //if (HttpContext.Current != null)
            //{
            //    Console.WriteLine("Request.Url.LocalPath: " + HttpContext.Current.Request.Url.LocalPath);
            //    Console.WriteLine("Request.Url.Host: " + HttpContext.Current.Request.Url.Host);
            //    Console.WriteLine("Request.FilePath: " + HttpContext.Current.Request.FilePath);
            //    Console.WriteLine("Request.Path: " + HttpContext.Current.Request.Path);
            //    Console.WriteLine("Request.RawUrl: " + HttpContext.Current.Request.RawUrl);
            //    Console.WriteLine("Request.Url: " + HttpContext.Current.Request.Url);
            //    Console.WriteLine("Request.Url.Port: " + HttpContext.Current.Request.Url.Port);
            //    Console.WriteLine("Request.ApplicationPath: " + HttpContext.Current.Request.ApplicationPath);
            //    Console.WriteLine("Request.PhysicalPath: " + HttpContext.Current.Request.PhysicalPath);
            //}
            //Console.WriteLine("HttpRuntime.AppDomainAppPath: " + HttpRuntime.AppDomainAppPath);
            //Console.WriteLine("HttpRuntime.AppDomainAppVirtualPath: " + HttpRuntime.AppDomainAppVirtualPath);
            //Console.WriteLine("HostingEnvironment.ApplicationPhysicalPath: " + HostingEnvironment.ApplicationPhysicalPath);
            //Console.WriteLine("HostingEnvironment.ApplicationVirtualPath: " + HostingEnvironment.ApplicationVirtualPath);

            #endregion
            
            return this;
        }