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; } } }
public NetHttpRequest(WebHostWorkerRequest wr, NetHttpContext context) : base(new HttpRequest(null, "http://contoso", null)) { Context = context; _netContext = wr.NetContext; _netRequest = _netContext.Request; }
private void FireApplicationOnStart(NetHttpContext context) { if (_onStartMethod != null) { var application = GetSpecialApplicationInstance(null); application.ProcessSpecialRequest(context, _onStartMethod, _onStartParamCount, this, EventArgs.Empty, null); RecycleSpecialApplicationInstance(application); } }
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); }
private void EnsureAppStartCalled(NetHttpContext context) { if (!_appOnStartCalled) { lock (this) if (!_appOnStartCalled) { FireApplicationOnStart(context); _appOnStartCalled = true; } } }
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); }
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); }
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); } } }
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; } }
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; } }
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); } } }
internal INetHttpHandler MapHttpHandler(NetHttpContext context, string p, string p_2, string p_3, bool p_4) { return(null); }
private static void EnsureFirstRequestInit(NetHttpContext context) { }
//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; }
public NetHttpResponse(WebHostWorkerRequest wr, NetHttpContext context) { Context = context; _netContext = wr.NetContext; _netResponse = _netContext.Response; }