internal HostingMessageProperty(HostedHttpRequestAsyncResult result) { if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { if ((result.ImpersonationContext != null) && result.ImpersonationContext.IsImpersonated) { this.impersonationContext = result.ImpersonationContext; this.impersonationContext.AddRef(); } this.currentThreadData = result.HostedThreadData; } this.OriginalRequestUri = result.OriginalRequestUri; }
private static void UnsafeApplyData(HostedThreadData data) { CallContext.HostContext = data.httpContext; Thread currentThread = Thread.CurrentThread; if (currentThread.CurrentCulture != data.cultureInfo) { currentThread.CurrentCulture = data.cultureInfo; } if (currentThread.CurrentUICulture != data.uiCultureInfo) { currentThread.CurrentUICulture = data.uiCultureInfo; } }
internal HostingMessageProperty(HostedHttpRequestAsyncResult result) { Fx.Assert(ServiceHostingEnvironment.IsHosted, "should only be called in the hosted path"); if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { if (result.ImpersonationContext != null && result.ImpersonationContext.IsImpersonated) { this.impersonationContext = result.ImpersonationContext; this.impersonationContext.AddRef(); } currentThreadData = result.HostedThreadData; } this.OriginalRequestUri = result.OriginalRequestUri; }
static void UnsafeApplyData(HostedThreadData data) { // We set the CallContext.HostContext directly instead of setting HttpContext.Current because // the latter uses a demand instead of a link demand, which is very expensive in partial trust. System.Runtime.Remoting.Messaging.CallContext.HostContext = data.httpContext; Thread currentThread = Thread.CurrentThread; if (currentThread.CurrentCulture != data.cultureInfo) { currentThread.CurrentCulture = data.cultureInfo; } if (currentThread.CurrentUICulture != data.uiCultureInfo) { currentThread.CurrentUICulture = data.uiCultureInfo; } }
public HostedHttpRequestAsyncResult(HttpApplication context, string aspNetRouteServiceVirtualPath, bool flowContext, bool ensureWFService, AsyncCallback callback, object state) : base(callback, state) { if (context == null) { throw FxTrace.Exception.ArgumentNull("context"); } AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); HostedAspNetEnvironment.TrySetWebSocketVersion(context); this.context = context; // WebSockets require the integrated pipeline mode and the WebSocket IIS module to be loaded. If these conditions // are not met, the HttpContext.IsWebSocketRequest property throws. Also, if these conditions are not met, // we do not let WebSocket listeners to be started (we fail the service activation), so setting the 'isWebSocketRequest' flag // to false in this case will not create confusion (or make troubleshooting difficult). this.isWebSocketRequest = HttpRuntime.UsingIntegratedPipeline && AspNetEnvironment.Current.IsWebSocketModuleLoaded && this.context.Context.IsWebSocketRequest; this.flowContext = flowContext; if (ensureWFService) { // check for CBA scenario. if true, service should be handled by WCF instead of WF, // set this.ensureWFservice to false if (ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath)) { this.ensureWFService = false; } else { this.ensureWFService = true; } } if (!string.IsNullOrEmpty(aspNetRouteServiceVirtualPath)) { // aspnet routing can hijack CBA request as we append {*pathInfo} to urlpattern and there is no real file for CBA // check for CBA scenario. if the request is hijacked. i.e., // 1) route maps to a virtual directory: // aspNetRouteServiceVirtualPath <> context.Request.AppRelativeCurrentExecutionFilePath == configurationBasedServiceVirtualPath // if RouteExistingFiles <> true, set aspnetRouteServiceVirtualPath to null so that the request will be treated as CBA // if RouteExistingFiles == true, this hijack is by-design, do nothing // 2) route maps to a CBA entry: // aspNetRouteServiceVirtualPath == context.Request.AppRelativeCurrentExecutionFilePath == configurationBasedServiceVirtualPath // we will use RouteExistingFiles to decide which service should be activated. We do it in ServiceHostingEnviroment.HostingManager, // as we cannot pass this info to the latter. if (!RouteTable.Routes.RouteExistingFiles && ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath)) { this.AspNetRouteServiceVirtualPath = null; } else { this.AspNetRouteServiceVirtualPath = aspNetRouteServiceVirtualPath; } } // If this is a DEBUG request, complete right away and let ASP.NET handle it. string method = context.Request.HttpMethod ?? ""; char firstMethodChar = method.Length == 5 ? method[0] : '\0'; if ((firstMethodChar == 'd' || firstMethodChar == 'D') && string.Compare(method, "DEBUG", StringComparison.OrdinalIgnoreCase) == 0) { if (DiagnosticUtility.ShouldTraceVerbose) { TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.WebHostDebugRequest, SR.TraceCodeWebHostDebugRequest, this); } this.state = State.Completed; Complete(true, null); return; } this.impersonationContext = new HostedImpersonationContext(); if (flowContext) { if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { // Capture HttpContext/culture context if necessary. Can be used later by HostedHttpInput to re-apply // the culture during dispatch. Also flowed here. hostedThreadData = new HostedThreadData(); } } // Set this up before calling IncrementRequestCount so if it fails, we don't leak a count. Action<object> iotsCallback = (AspNetPartialTrustHelpers.NeedPartialTrustInvoke || flowContext) ? WaitOnBeginRequestWithFlow : WaitOnBeginRequest; // Tell ASPNET to by-pass all the other events so no other http modules will // be invoked, Indigo basically takes over the request completely. This should // only be called in non-AspNetCompatibilityEnabled mode. if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled && !this.ensureWFService) { context.CompleteRequest(); } // Prevent ASP.NET from generating thread aborts in relation to this request. context.Server.ScriptTimeout = int.MaxValue; ServiceHostingEnvironment.IncrementRequestCount(ref this.eventTraceActivity, context.Request.AppRelativeCurrentExecutionFilePath); IOThreadScheduler.ScheduleCallbackLowPriNoFlow(iotsCallback, this); }
public HostedAspNetContext(HostedThreadData newData) { oldData = new HostedThreadData(); HostedThreadData.UnsafeApplyData(newData); }
public void Dispose() { HostedThreadData.UnsafeApplyData(this.oldData); }
public HostedAspNetContext(HostedThreadData newData) { HostedThreadData.UnsafeApplyData(newData); }
public HostedHttpRequestAsyncResult(HttpApplication context, string aspNetRouteServiceVirtualPath, bool flowContext, bool ensureWFService, AsyncCallback callback, object state) : base(callback, state) { if (context == null) { throw FxTrace.Exception.ArgumentNull("context"); } AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); HostedAspNetEnvironment.TrySetWebSocketVersion(context); this.context = context; // WebSockets require the integrated pipeline mode and the WebSocket IIS module to be loaded. If these conditions // are not met, the HttpContext.IsWebSocketRequest property throws. Also, if these conditions are not met, // we do not let WebSocket listeners to be started (we fail the service activation), so setting the 'isWebSocketRequest' flag // to false in this case will not create confusion (or make troubleshooting difficult). this.isWebSocketRequest = HttpRuntime.UsingIntegratedPipeline && AspNetEnvironment.Current.IsWebSocketModuleLoaded && this.context.Context.IsWebSocketRequest; this.flowContext = flowContext; if (ensureWFService) { // check for CBA scenario. if true, service should be handled by WCF instead of WF, // set this.ensureWFservice to false if (ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath)) { this.ensureWFService = false; } else { this.ensureWFService = true; } } if (!string.IsNullOrEmpty(aspNetRouteServiceVirtualPath)) { // aspnet routing can hijack CBA request as we append {*pathInfo} to urlpattern and there is no real file for CBA // check for CBA scenario. if the request is hijacked. i.e., // 1) route maps to a virtual directory: // aspNetRouteServiceVirtualPath <> context.Request.AppRelativeCurrentExecutionFilePath == configurationBasedServiceVirtualPath // if RouteExistingFiles <> true, set aspnetRouteServiceVirtualPath to null so that the request will be treated as CBA // if RouteExistingFiles == true, this hijack is by-design, do nothing // 2) route maps to a CBA entry: // aspNetRouteServiceVirtualPath == context.Request.AppRelativeCurrentExecutionFilePath == configurationBasedServiceVirtualPath // we will use RouteExistingFiles to decide which service should be activated. We do it in ServiceHostingEnviroment.HostingManager, // as we cannot pass this info to the latter. if (!RouteTable.Routes.RouteExistingFiles && ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath)) { this.AspNetRouteServiceVirtualPath = null; } else { this.AspNetRouteServiceVirtualPath = aspNetRouteServiceVirtualPath; } } // If this is a DEBUG request, complete right away and let ASP.NET handle it. string method = context.Request.HttpMethod ?? ""; char firstMethodChar = method.Length == 5 ? method[0] : '\0'; if ((firstMethodChar == 'd' || firstMethodChar == 'D') && string.Compare(method, "DEBUG", StringComparison.OrdinalIgnoreCase) == 0) { if (DiagnosticUtility.ShouldTraceVerbose) { TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.WebHostDebugRequest, SR.TraceCodeWebHostDebugRequest, this); } this.state = State.Completed; Complete(true, null); return; } this.impersonationContext = new HostedImpersonationContext(); if (flowContext) { if (ServiceHostingEnvironment.AspNetCompatibilityEnabled) { // Capture HttpContext/culture context if necessary. Can be used later by HostedHttpInput to re-apply // the culture during dispatch. Also flowed here. hostedThreadData = new HostedThreadData(); } } // Set this up before calling IncrementRequestCount so if it fails, we don't leak a count. Action <object> iotsCallback = (AspNetPartialTrustHelpers.NeedPartialTrustInvoke || flowContext) ? WaitOnBeginRequestWithFlow : WaitOnBeginRequest; // Tell ASPNET to by-pass all the other events so no other http modules will // be invoked, Indigo basically takes over the request completely. This should // only be called in non-AspNetCompatibilityEnabled mode. if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled && !this.ensureWFService) { context.CompleteRequest(); } // Prevent ASP.NET from generating thread aborts in relation to this request. context.Server.ScriptTimeout = int.MaxValue; ServiceHostingEnvironment.IncrementRequestCount(ref this.eventTraceActivity, context.Request.AppRelativeCurrentExecutionFilePath); IOThreadScheduler.ScheduleCallbackLowPriNoFlow(iotsCallback, this); }