Ejemplo n.º 1
0
 private void FinishRequest(HttpWorkerRequest wr, HttpContext context, Exception e)
 {
   HttpResponse response = context.Response;
   if (EtwTrace.IsTraceEnabled(5, 1))
     EtwTrace.Trace(EtwTraceType.ETW_TYPE_END_HANDLER, context.WorkerRequest);
   HttpRuntime.SetExecutionTimePerformanceCounter(context);
   if (e == null)
   {
     using (new ClientImpersonationContext(context, false))
     {
       try
       {
         response.FinalFlushAtTheEndOfRequestProcessing();
       }
       catch (Exception ex)
       {
         e = ex;
       }
     }
   }
   if (e != null)
   {
     using (new DisposableHttpContextWrapper(context))
     {
       context.DisableCustomHttpEncoder = true;
       if (this._appOfflineMessage != null)
       {
         try
         {
           HttpRuntime.ReportAppOfflineErrorMessage(response, this._appOfflineMessage);
           response.FinalFlushAtTheEndOfRequestProcessing();
         }
         catch
         {
         }
       }
       else
       {
         using (new ApplicationImpersonationContext())
         {
           try
           {
             try
             {
               response.ReportRuntimeError(e, true, false);
             }
             catch (Exception ex)
             {
               response.ReportRuntimeError(ex, false, false);
             }
             response.FinalFlushAtTheEndOfRequestProcessing();
           }
           catch
           {
           }
         }
       }
     }
   }
   this._firstRequestCompleted = true;
   if (this._hostingInitFailed)
     HttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.HostingEnvironment, "HostingInit error");
   int statusCode = response.StatusCode;
   HttpRuntime.UpdatePerfCounters(statusCode);
   context.FinishRequestForCachedPathData(statusCode);
   try
   {
     wr.EndOfRequest();
   }
   catch (Exception ex)
   {
     WebBaseEvent.RaiseRuntimeError(ex, (object) this);
   }
   HostingEnvironment.DecrementBusyCount();
   Interlocked.Decrement(ref this._activeRequestCount);
   if (this._requestQueue == null)
     return;
   this._requestQueue.ScheduleMoreWorkIfNeeded();
 }
Ejemplo n.º 2
0
 private void ProcessRequestInternal(HttpWorkerRequest wr)
 {
   Interlocked.Increment(ref this._activeRequestCount);
   if (this._disposingHttpRuntime)
   {
     try
     {
       wr.SendStatus(503, "Server Too Busy");
       wr.SendKnownResponseHeader(12, "text/html; charset=utf-8");
       byte[] bytes = Encoding.ASCII.GetBytes("<html><body>Server Too Busy</body></html>");
       wr.SendResponseFromMemory(bytes, bytes.Length);
       wr.FlushResponse(true);
       wr.EndOfRequest();
     }
     finally
     {
       Interlocked.Decrement(ref this._activeRequestCount);
     }
   }
   else
   {
     HttpContext context;
     try
     {
       context = new HttpContext(wr, false);
     }
     catch
     {
       try
       {
         wr.SendStatus(400, "Bad Request");
         wr.SendKnownResponseHeader(12, "text/html; charset=utf-8");
         byte[] bytes = Encoding.ASCII.GetBytes("<html><body>Bad Request</body></html>");
         wr.SendResponseFromMemory(bytes, bytes.Length);
         wr.FlushResponse(true);
         wr.EndOfRequest();
         return;
       }
       finally
       {
         Interlocked.Decrement(ref this._activeRequestCount);
       }
     }
     wr.SetEndOfSendNotification(this._asyncEndOfSendCallback, (object) context);
     HostingEnvironment.IncrementBusyCount();
     try
     {
       try
       {
         this.EnsureFirstRequestInit(context);
       }
       catch
       {
         if (!context.Request.IsDebuggingRequest)
           throw;
       }
       context.Response.InitResponseWriter();
       IHttpHandler applicationInstance = HttpApplicationFactory.GetApplicationInstance(context);
       if (applicationInstance == null)
         throw new HttpException(System.Web.SR.GetString("Unable_create_app_object"));
       if (EtwTrace.IsTraceEnabled(5, 1))
         EtwTrace.Trace(EtwTraceType.ETW_TYPE_START_HANDLER, context.WorkerRequest, applicationInstance.GetType().FullName, "Start");
       if (applicationInstance is IHttpAsyncHandler)
       {
         IHttpAsyncHandler httpAsyncHandler = (IHttpAsyncHandler) applicationInstance;
         context.AsyncAppHandler = httpAsyncHandler;
         httpAsyncHandler.BeginProcessRequest(context, this._handlerCompletionCallback, (object) context);
       }
       else
       {
         applicationInstance.ProcessRequest(context);
         this.FinishRequest(context.WorkerRequest, context, (Exception) null);
       }
     }
     catch (Exception ex)
     {
       context.Response.InitResponseWriter();
       this.FinishRequest(wr, context, ex);
     }
   }
 }