internal void Execute(IHttpHandler handler, TextWriter writer, bool preserveForm, string exePath, string queryString, bool isTransfer, bool isInclude)
{
#if !TARGET_J2EE
// If the target handler is not Page, the transfer must not occur.
// InTransit == true means we're being called from Transfer
bool is_static = (handler is StaticFileHandler);
if (isTransfer && !(handler is Page) && !is_static)
{
throw new HttpException("Transfer is only allowed to .aspx and static files");
}
#endif
HttpRequest request = context.Request;
string oldQuery = request.QueryStringRaw;
if (queryString != null)
{
request.QueryStringRaw = queryString;
}
else if (!preserveForm)
{
request.QueryStringRaw = String.Empty;
}
HttpResponse response = context.Response;
WebROCollection oldForm = request.Form as WebROCollection;
if (!preserveForm)
{
request.SetForm(new WebROCollection());
}
TextWriter output = writer;
if (output == null)
{
output = response.Output;
}
TextWriter previous = response.SetTextWriter(output);
string oldExePath = request.CurrentExecutionFilePath;
bool oldIsInclude = context.IsProcessingInclude;
try
{
context.PushHandler(handler);
if (is_static) // Not sure if this should apply to Page too
{
request.SetFilePath(exePath);
}
request.SetCurrentExePath(exePath);
context.IsProcessingInclude = isInclude;
if (!(handler is IHttpAsyncHandler))
{
handler.ProcessRequest(context);
}
else
{
IHttpAsyncHandler asyncHandler = (IHttpAsyncHandler)handler;
IAsyncResult ar = asyncHandler.BeginProcessRequest(context, null, null);
WaitHandle asyncWaitHandle = ar != null ? ar.AsyncWaitHandle : null;
if (asyncWaitHandle != null)
{
asyncWaitHandle.WaitOne();
}
asyncHandler.EndProcessRequest(ar);
}
}
finally
{
if (oldQuery != request.QueryStringRaw)
{
if (oldQuery != null && oldQuery.Length > 0)
{
oldQuery = oldQuery.Substring(1); // Ignore initial '?'
request.QueryStringRaw = oldQuery; // which is added here.
}
else
{
request.QueryStringRaw = String.Empty;
}
}
response.SetTextWriter(previous);
if (!preserveForm)
{
request.SetForm(oldForm);
}
context.PopHandler();
request.SetCurrentExePath(oldExePath);
context.IsProcessingInclude = oldIsInclude;
}
}