/// <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 (this._responseWriter == null) { this._builder = new StringBuilder(); this._responseWriter = new StringWriter(this._builder); } SetHttpRuntimeInternals(); string query = ExtractQueryStringPart(url); if (formVariables != null) { this._formVars.Add(formVariables); } if (this._formVars.Count > 0) { httpVerb = HttpVerb.POST; //Need to enforce this. } if (headers != null) { this._headers.Add(headers); } this._workerRequest = new SimulatedHttpRequest(this.ApplicationPath, this.PhysicalApplicationPath, this.PhysicalPath, this.Page, query, this._responseWriter, this.Host, this.Port, httpVerb.ToString()); this._workerRequest.CurrentExecutionPath = this._currentExecutionPath; this._workerRequest.Form.Add(this._formVars); this._workerRequest.Headers.Add(this._headers); this._workerRequest.Cookies.Add(this._cookies); if (this._referer != null) { this._workerRequest.SetReferer(this._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); //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; }
/// <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 (this._responseWriter == null) { this._builder = new StringBuilder(); this._responseWriter = new StringWriter(this._builder); } SetHttpRuntimeInternals(); string query = ExtractQueryStringPart(url); if (formVariables != null) { this._formVars.Add(formVariables); } if (this._formVars.Count > 0) { httpVerb = HttpVerb.POST; //Need to enforce this. } if (headers != null) { this._headers.Add(headers); } this._workerRequest = new SimulatedHttpRequest(ApplicationPath, PhysicalApplicationPath, PhysicalPath, Page, query, this._responseWriter, Host, Port, httpVerb.ToString()); this._workerRequest.CurrentExecutionPath = this._currentExecutionPath; this._workerRequest.Form.Add(this._formVars); this._workerRequest.Headers.Add(this._headers); this._workerRequest.Cookies.Add(this._cookies); if (this._referer != null) { this._workerRequest.SetReferer(this._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); //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); }