Ejemplo n.º 1
0
 internal void InitSpecial(NetHttpContext context, NetHttpApplicationState state, NetHttpApplicationFactory factory, MethodInfo[] handlers)
 {
     _state   = state;
     _factory = factory;
     try
     {
         if (context != null)
         {
             _initContext = context;
             _initContext.NetApplicationInstance = this;
         }
         InitAppLevelCulture();
         if (handlers != null)
         {
             HookupEventHandlersForApplicationAndModules(handlers);
         }
     }
     finally
     {
         _initSpecialCompleted = true;
         if (_initContext != null)
         {
             _initContext.NetApplicationInstance = null;
             _initContext = null;
         }
     }
 }
Ejemplo n.º 2
0
 public NetHttpRequest(WebHostWorkerRequest wr, NetHttpContext context)
     : base(new HttpRequest(null, "http://contoso", null))
 {
     Context     = context;
     _netContext = wr.NetContext;
     _netRequest = _netContext.Request;
 }
Ejemplo n.º 3
0
 private void FireApplicationOnStart(NetHttpContext context)
 {
     if (_onStartMethod != null)
     {
         var application = GetSpecialApplicationInstance(null);
         application.ProcessSpecialRequest(context, _onStartMethod, _onStartParamCount, this, EventArgs.Empty, null);
         RecycleSpecialApplicationInstance(application);
     }
 }
Ejemplo n.º 4
0
        IAsyncResult INetHttpAsyncHandler.BeginProcessRequest(NetHttpContext context, AsyncCallback cb, object extraData)
        {
            _context = context;
            _context.NetApplicationInstance = this;
            _stepManager.InitRequest();
            var result = new NetHttpAsyncResult(cb, extraData);

            AsyncResult = result;
            ResumeSteps(null);
            return(result);
        }
Ejemplo n.º 5
0
 private void EnsureAppStartCalled(NetHttpContext context)
 {
     if (!_appOnStartCalled)
     {
         lock (this)
             if (!_appOnStartCalled)
             {
                 FireApplicationOnStart(context);
                 _appOnStartCalled = true;
             }
     }
 }
Ejemplo n.º 6
0
        private NetHttpApplication GetSpecialApplicationInstance(NetHttpContext context)
        {
            NetHttpApplication application = null;

            lock (_freeSpecialInstances)
                if (_numFreeSpecialInstances > 0)
                {
                    application = (NetHttpApplication)_freeSpecialInstances.Pop();
                    _numFreeSpecialInstances--;
                }
            if (application == null)
            {
                application = (NetHttpApplication)NetHttpRuntime.CreateNonPublicInstance(_applicationType, null);
                application.InitSpecial(context, _state, this, _eventHandlerMethods);
            }
            return(application);
        }
Ejemplo n.º 7
0
 internal void ReleaseAppInstance()
 {
     if (_context != null)
     {
         _context.ClearReferences();
         if (_timeoutManagerInitialized)
         {
             HttpListenerHost.RequestTimeoutManager.Remove(_context.WorkerRequest);
             _timeoutManagerInitialized = false;
         }
     }
     RecycleHandlers();
     if (AsyncResult != null)
     {
         AsyncResult = null;
     }
     _context = null;
     AppEvent = null;
     ApplicationFactory.RecycleApplicationInstance(this);
 }
Ejemplo n.º 8
0
        internal NetHttpApplication GetApplicationInstance(NetHttpWorkerRequest wr, NetHttpContext context)
        {
            EnsureInited();
            EnsureAppStartCalled(context);
            //
            NetHttpApplication application = null;

            lock (_freeInstances)
                if (_numFreeInstances > 0)
                {
                    application = (NetHttpApplication)_freeInstances.Pop();
                    _numFreeInstances--;
                }
            if (application == null)
            {
                application = (NetHttpApplication)NetHttpRuntime.CreateNonPublicInstance(_applicationType, null);
                application.InitInternal(wr, context, _state, this, _eventHandlerMethods);
            }
            return(application);
        }
        internal static void RejectRequestNow(WebHost host, WebHostWorkerRequest wr, bool silent)
        {
            var context = new NetHttpContext(wr, false);

            wr.SetEndOfSendNotification(_asyncEndOfSendCallback, context);
            Console.WriteLine("a:Request");
            Interlocked.Increment(ref host._activeRequests);
            if (silent)
            {
                ((NetHttpResponse)context.Response).InitResponseWriter();
                FinishRequest(host, wr, context, null);
            }
            else
            {
                try { throw new HttpException(0x1f7, "Server_too_busy"); }
                catch (Exception ex)
                {
                    ((NetHttpResponse)context.Response).InitResponseWriter();
                    FinishRequest(host, wr, context, ex);
                }
            }
        }
Ejemplo n.º 10
0
 internal void InitInternal(NetHttpWorkerRequest wr, NetHttpContext context, NetHttpApplicationState state, NetHttpApplicationFactory factory, MethodInfo[] handlers)
 {
     _state   = state;
     _factory = factory;
     try
     {
         _initContext = context;
         _initContext.NetApplicationInstance = this;
         InitModules(wr);
         if (handlers != null)
         {
             HookupEventHandlersForApplicationAndModules(handlers);
         }
         _context = context;
         if (_context != null)
         {
             _context.HideRequestResponse = true;
         }
         _hideRequestResponse = true;
         try { Init(); }
         catch (Exception exception) { RecordError(exception); }
         if (_context != null)
         {
             _context.HideRequestResponse = false;
         }
         _hideRequestResponse     = false;
         _context                 = null;
         _resumeStepsWaitCallback = new WaitCallback(ResumeStepsWaitCallback);
         _stepManager             = new ApplicationNetStepManager(this);
         _stepManager.BuildSteps(_resumeStepsWaitCallback);
     }
     finally
     {
         _initInternalCompleted = true;
         _initContext.NetApplicationInstance = null;
         _initContext = null;
     }
 }
Ejemplo n.º 11
0
 internal void ProcessSpecialRequest(NetHttpContext context, MethodInfo method, int paramCount, object eventSource, EventArgs eventArgs, HttpSessionStateBase session)
 {
     _context = context;
     if (_context != null)
     {
         _context.HideRequestResponse = true;
     }
     _hideRequestResponse = true;
     _session             = session;
     _lastError           = null;
     try
     {
         SetAppLevelCulture();
         InvokeMethodWithAssert(method, paramCount, eventSource, eventArgs);
     }
     catch (Exception exception)
     {
         var innerException = (exception is TargetInvocationException ? exception.InnerException : exception);
         RecordError(innerException);
     }
     finally
     {
         if (_state != null)
         {
             _state.EnsureUnLock();
         }
         RestoreAppLevelCulture();
         if (_context != null)
         {
             _context.HideRequestResponse = false;
         }
         _hideRequestResponse = false;
         _context             = null;
         _session             = null;
         _lastError           = null;
         _appEvent            = null;
     }
 }
Ejemplo n.º 12
0
 internal void EnsureAppStartCalledForIntegratedMode(NetHttpContext context, NetHttpApplication application)
 {
     if (!_appOnStartCalled)
     {
         Exception innerException = null;
         lock (this)
         {
             if (!_appOnStartCalled)
             {
                 if (_onStartMethod != null)
                 {
                     application.ProcessSpecialRequest(context, _onStartMethod, _onStartParamCount, this, EventArgs.Empty, null);
                 }
             }
             _appOnStartCalled = true;
             innerException    = context.Error;
         }
         if (innerException != null)
         {
             throw new HttpException(innerException.Message, innerException);
         }
     }
 }
        private static void FinishRequest(WebHost host, NetHttpWorkerRequest wr, NetHttpContext context, Exception e)
        {
            var response = (NetHttpResponse)context.Response;

            if (e == null)
            {
                try { response.FinalFlushAtTheEndOfRequestProcessing(); }
                catch (Exception e2) { e = e2; }
            }
            if (e != null)
            {
                context.DisableCustomHttpEncoder = true;
                try
                {
                    try { response.ReportRuntimeError(e, true, false); }
                    catch (Exception e2) { response.ReportRuntimeError(e2, false, false); }
                    response.FinalFlushAtTheEndOfRequestProcessing();
                }
                catch { }
            }
            _firstRequestCompleted = true;
            int statusCode = response.StatusCode;

            //context.FinishRequestForCachedPathData(statusCode);
            try { wr.EndOfRequest(); }
            catch (Exception e3) { RaiseRuntimeError(e3, wr); }
            Console.WriteLine("d:Request");
            Interlocked.Decrement(ref host._activeRequests);
            if (WebHost.UseThreading)
            {
                if (host._requestQueue != null)
                {
                    host._requestQueue.ScheduleMoreWorkIfNeeded();
                }
            }
        }
        internal static void ProcessRequestNow(WebHost host, WebHostWorkerRequest wr, NetHttpApplicationFactory applicationFactory)
        {
            wr.ResetStartTime();
            NetHttpContext context;

            try { context = new NetHttpContext(wr); }
            catch
            {
                wr.SendStatus(400, "Bad Request");
                wr.SendKnownResponseHeader(12, "text/html; charset=utf-8");
                var bytes = Encoding.ASCII.GetBytes("<html><body>Bad Request</body></html>");
                wr.SendResponseFromMemory(bytes, bytes.Length);
                wr.FlushResponse(true);
                wr.EndOfRequest();
                return;
            }
            Console.WriteLine("a:Request");
            wr.SetEndOfSendNotification(_asyncEndOfSendCallback, context);
            Interlocked.Increment(ref host._activeRequests);
            NetHttpApplication application = null;

            try
            {
                try { EnsureFirstRequestInit(context); }
                catch
                {
                    if (!((NetHttpRequest)context.Request).IsDebuggingRequest)
                    {
                        throw;
                    }
                }
                ((NetHttpResponse)context.Response).InitResponseWriter();
                application = applicationFactory.GetApplicationInstance(wr, context);
                if (application == null)
                {
                    throw new HttpException("Unable_create_app_object");
                }
                if (application is INetHttpAsyncHandler)
                {
                    var handler2 = (INetHttpAsyncHandler)application;
                    context.AsyncAppHandler = handler2;
                    handler2.BeginProcessRequest(context, _handlerCompletionCallback, context);
                }
                else
                {
                    ((INetHttpHandler)application).ProcessRequest(context);
                    FinishRequest(host, context.WorkerRequest, context, null);
                }
            }
            catch (Exception ex)
            {
                ((NetHttpResponse)context.Response).InitResponseWriter();
                FinishRequest(host, wr, context, ex);
            }
            finally
            {
                if (application != null)
                {
                    applicationFactory.RecycleApplicationInstance(application);
                }
            }
        }
Ejemplo n.º 15
0
 internal INetHttpHandler MapHttpHandler(NetHttpContext context, string p, string p_2, string p_3, bool p_4)
 {
     return(null);
 }
Ejemplo n.º 16
0
 private static void EnsureFirstRequestInit(NetHttpContext context)
 {
 }
Ejemplo n.º 17
0
            //private bool _hasLeaveBeenCalled;
            //private ImpersonationContext _impersonationContext;
            //private HttpContext _savedContext;
            //private CultureInfo _savedCulture;
            //private IPrincipal _savedPrincipal;
            //private SynchronizationContext _savedSynchronizationContext;
            //private CultureInfo _savedUICulture;
            //private bool _setThread;
            //private CultureInfo _setThreadCulture;
            //private CultureInfo _setThreadUICulture;

            internal ThreadContext(NetHttpContext context)
            {
                _context = context;
            }
Ejemplo n.º 18
0
 public NetHttpResponse(WebHostWorkerRequest wr, NetHttpContext context)
 {
     Context      = context;
     _netContext  = wr.NetContext;
     _netResponse = _netContext.Response;
 }