/// <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();
string 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.CurrentExecutionPath = _currentExecutionPath;
_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);
//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;
}