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 WebHost(Type httpApplicationType, string uriPrefix) : base(null, uriPrefix) { //UseThreading = true; if (httpApplicationType == null) { throw new ArgumentNullException("httpApplicationType"); } if (!typeof(NetHttpApplication).IsAssignableFrom(httpApplicationType)) { throw new ArgumentOutOfRangeException("httpApplicationType", "must be of type NetHttpApplication"); } _httpApplicationType = httpApplicationType; _applicationFactory = new NetHttpApplicationFactory(_httpApplicationType); _runtime = new WebHostRuntime(this); }
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 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); } } }